PageRenderTime 28ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0079_input_library_to_job_table.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 42 lines | 29 code | 8 blank | 5 comment | 0 complexity | 4976db5f184b4e0c2dcffe498f546bdd MD5 | raw file
 1"""
 2Migration script to add the job_to_input_library_dataset 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
15JobToInputLibraryDatasetAssociation_table = Table( "job_to_input_library_dataset", metadata,
16    Column( "id", Integer, primary_key=True ),
17    Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
18    Column( "ldda_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), index=True ),
19    Column( "name", String(255) ) )
20
21def upgrade(migrate_engine):
22    metadata.bind = migrate_engine
23    print __doc__
24    metadata.reflect()
25
26    # Create the job_to_input_library_dataset table
27    try:
28        JobToInputLibraryDatasetAssociation_table.create()
29    except Exception, e:
30        print "Creating job_to_input_library_dataset table failed: %s" % str( e )
31        log.debug( "Creating job_to_input_library_dataset table failed: %s" % str( e ) )
32
33def downgrade(migrate_engine):
34    metadata.bind = migrate_engine
35    metadata.reflect()
36
37    # Drop the job_to_input_library_dataset table
38    try:
39        JobToInputLibraryDatasetAssociation_table.drop()
40    except Exception, e:
41        print str(e)
42        log.debug( "Dropping job_to_input_library_dataset table failed: %s" % str( e ) )