[2] | 1 | """ |
---|
| 2 | Migration script to add the suite column to the tool table. |
---|
| 3 | """ |
---|
| 4 | |
---|
| 5 | from sqlalchemy import * |
---|
| 6 | from sqlalchemy.orm import * |
---|
| 7 | from migrate import * |
---|
| 8 | from migrate.changeset import * |
---|
| 9 | |
---|
| 10 | import logging |
---|
| 11 | log = logging.getLogger( __name__ ) |
---|
| 12 | |
---|
| 13 | metadata = MetaData( migrate_engine ) |
---|
| 14 | db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) ) |
---|
| 15 | |
---|
| 16 | def upgrade(): |
---|
| 17 | print __doc__ |
---|
| 18 | metadata.reflect() |
---|
| 19 | |
---|
| 20 | # Create and initialize imported column in job table. |
---|
| 21 | Tool_table = Table( "tool", metadata, autoload=True ) |
---|
| 22 | c = Column( "suite", Boolean, default=False, index=True ) |
---|
| 23 | try: |
---|
| 24 | # Create |
---|
| 25 | c.create( Tool_table ) |
---|
| 26 | assert c is Tool_table.c.suite |
---|
| 27 | |
---|
| 28 | # Initialize. |
---|
| 29 | if migrate_engine.name == 'mysql' or migrate_engine.name == 'sqlite': |
---|
| 30 | default_false = "0" |
---|
| 31 | elif migrate_engine.name == 'postgres': |
---|
| 32 | default_false = "false" |
---|
| 33 | db_session.execute( "UPDATE tool SET suite=%s" % default_false ) |
---|
| 34 | |
---|
| 35 | except Exception, e: |
---|
| 36 | print "Adding suite column to the tool table failed: %s" % str( e ) |
---|
| 37 | log.debug( "Adding suite column to the tool table failed: %s" % str( e ) ) |
---|
| 38 | |
---|
| 39 | def downgrade(): |
---|
| 40 | metadata.reflect() |
---|
| 41 | |
---|
| 42 | # Drop imported column from job table. |
---|
| 43 | Tool_table = Table( "tool", metadata, autoload=True ) |
---|
| 44 | try: |
---|
| 45 | Tool_table.c.suite.drop() |
---|
| 46 | except Exception, e: |
---|
| 47 | print "Dropping column suite from the tool table failed: %s" % str( e ) |
---|
| 48 | log.debug( "Dropping column suite from the tool table failed: %s" % str( e ) ) |
---|