[2] | 1 | """ |
---|
| 2 | Migration script to add a deleted column to the following tables: |
---|
| 3 | library_info_association, library_folder_info_association, library_dataset_dataset_info_association. |
---|
| 4 | """ |
---|
| 5 | |
---|
| 6 | from sqlalchemy 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 | |
---|
| 15 | def upgrade(): |
---|
| 16 | print __doc__ |
---|
| 17 | metadata.reflect() |
---|
| 18 | |
---|
| 19 | LibraryInfoAssociation_table = Table( "library_info_association", metadata, autoload=True ) |
---|
| 20 | c = Column( "deleted", Boolean, index=True, default=False ) |
---|
| 21 | c.create( LibraryInfoAssociation_table ) |
---|
| 22 | assert c is LibraryInfoAssociation_table.c.deleted |
---|
| 23 | cmd = "UPDATE library_info_association SET deleted = false" |
---|
| 24 | try: |
---|
| 25 | db_session.execute( cmd ) |
---|
| 26 | except Exception, e: |
---|
| 27 | log.debug( "deleted to false in library_info_association failed: %s" % ( str( e ) ) ) |
---|
| 28 | |
---|
| 29 | LibraryFolderInfoAssociation_table = Table( "library_folder_info_association", metadata, autoload=True ) |
---|
| 30 | c = Column( "deleted", Boolean, index=True, default=False ) |
---|
| 31 | c.create( LibraryFolderInfoAssociation_table ) |
---|
| 32 | assert c is LibraryFolderInfoAssociation_table.c.deleted |
---|
| 33 | cmd = "UPDATE library_folder_info_association SET deleted = false" |
---|
| 34 | try: |
---|
| 35 | db_session.execute( cmd ) |
---|
| 36 | except Exception, e: |
---|
| 37 | log.debug( "deleted to false in library_folder_info_association failed: %s" % ( str( e ) ) ) |
---|
| 38 | |
---|
| 39 | LibraryDatasetDatasetInfoAssociation_table = Table( "library_dataset_dataset_info_association", metadata, autoload=True ) |
---|
| 40 | c = Column( "deleted", Boolean, index=True, default=False ) |
---|
| 41 | c.create( LibraryDatasetDatasetInfoAssociation_table ) |
---|
| 42 | assert c is LibraryDatasetDatasetInfoAssociation_table.c.deleted |
---|
| 43 | cmd = "UPDATE library_dataset_dataset_info_association SET deleted = false" |
---|
| 44 | try: |
---|
| 45 | db_session.execute( cmd ) |
---|
| 46 | except Exception, e: |
---|
| 47 | log.debug( "deleted to false in library_dataset_dataset_info_association failed: %s" % ( str( e ) ) ) |
---|
| 48 | |
---|
| 49 | def downgrade(): |
---|
| 50 | pass |
---|