PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0071_add_history_and_workflow_to_sample.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 46 lines | 45 code | 0 blank | 1 comment | 0 complexity | f68fca673dbd9a179936d6cab6b4092a MD5 | raw file
 1"""
 2Migration script to add 'workflow' and 'history' columns for a sample.
 3"""
 4
 5from sqlalchemy import *
 6from sqlalchemy.orm import *
 7from migrate import *
 8from migrate.changeset import *
 9from galaxy.model.custom_types import *
10
11import logging
12log = logging.getLogger( __name__ )
13
14metadata = MetaData()
15
16def upgrade(migrate_engine):
17    metadata.bind = migrate_engine
18    print __doc__
19    metadata.reflect()
20    try:
21        Sample_table = Table( "sample", metadata, autoload=True )
22        c1 = Column( "workflow", JSONType, nullable=True )
23        c2 = Column( "history_id", Integer, ForeignKey( "history.id" ), nullable=True)
24        c1.create( Sample_table )
25        c2.create( Sample_table )
26        assert c1 is Sample_table.c.workflow
27        assert c2 is Sample_table.c.history_id
28    except Exception, e:
29        print "Adding history and workflow columns to sample table failed: %s" % str( e )
30        log.debug( "Adding history and workflow columns to sample table failed: %s" % str( e ) )
31
32def downgrade(migrate_engine):
33    metadata.bind = migrate_engine
34    metadata.reflect()
35    try:
36        Sample_table = Table( "sample", metadata, autoload=True )
37        Sample_table.c.workflow.drop()
38    except Exception, e:
39        print "Dropping workflow column from sample table failed: %s" % str( e )
40        log.debug( "Dropping workflow column from sample table failed: %s" % str( e ) )
41    try:
42        Sample_table = Table( "sample", metadata, autoload=True )
43        Sample_table.c.history_id.drop()
44    except Exception, e:
45        print "Dropping history column from sample table failed: %s" % str( e )
46        log.debug( "Dropping history column from sample table failed: %s" % str( e ) )