PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0073_add_ldda_to_implicit_conversion_table.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 40 lines | 38 code | 1 blank | 1 comment | 1 complexity | 2f2a1f9317e6baf28b2fd29bb0d80d1b MD5 | raw file
 1"""
 2Migration script to add 'ldda_parent_id' column to the implicitly_converted_dataset_association table.
 3"""
 4
 5from sqlalchemy import *
 6from sqlalchemy.orm import *
 7from migrate import *
 8from migrate.changeset import *
 9
10import logging
11log = logging.getLogger( __name__ )
12
13metadata = MetaData()
14
15def upgrade(migrate_engine):
16    metadata.bind = migrate_engine
17    print __doc__
18    metadata.reflect()
19    try:
20        Implicitly_converted_table = Table( "implicitly_converted_dataset_association", metadata, autoload=True )
21        if migrate_engine.name != 'sqlite':
22            c = Column( "ldda_parent_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), index=True, nullable=True )
23        else:
24            #Can't use the ForeignKey in sqlite.
25            c = Column( "ldda_parent_id", Integer, index=True, nullable=True )
26        c.create( Implicitly_converted_table, index_name="ix_implicitly_converted_dataset_assoc_ldda_parent_id")
27        assert c is Implicitly_converted_table.c.ldda_parent_id
28    except Exception, e:
29        print "Adding ldda_parent_id column to implicitly_converted_dataset_association table failed: %s" % str( e )
30        log.debug( "Adding ldda_parent_id column to implicitly_converted_dataset_association table failed: %s" % str( e ) )
31
32def downgrade(migrate_engine):
33    metadata.bind = migrate_engine
34    metadata.reflect()
35    try:
36        Implicitly_converted_table = Table( "implicitly_converted_dataset_association", metadata, autoload=True )
37        Implicitly_converted_table.c.ldda_parent_id.drop()
38    except Exception, e:
39        print "Dropping ldda_parent_id column from implicitly_converted_dataset_association table failed: %s" % str( e )
40        log.debug( "Dropping ldda_parent_id column from implicitly_converted_dataset_association table failed: %s" % str( e ) )