PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0016_v0015_mysql_index_fix.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 53 lines | 51 code | 0 blank | 2 comment | 2 complexity | 903c2c08965b0831ba2599b82e5912a0 MD5 | raw file
 1"""
 2This script fixes a problem introduced in 0015_tagging.py. MySQL has a name length
 3limit and thus the index "ix_hda_ta_history_dataset_association_id" has to be
 4manually created.
 5"""
 6
 7from sqlalchemy import *
 8from migrate import *
 9
10import datetime
11now = datetime.datetime.utcnow
12
13# Need our custom types, but don't import anything else from model
14from galaxy.model.custom_types import *
15
16import logging
17log = logging.getLogger( __name__ )
18
19metadata = MetaData()
20
21def display_migration_details():
22    print ""
23    print "This script fixes a problem introduced in 0015_tagging.py.  MySQL has a"
24    print "name length limit and thus the index 'ix_hda_ta_history_dataset_association_id'"
25    print "has to be manually created."
26
27HistoryDatasetAssociationTagAssociation_table = Table( "history_dataset_association_tag_association", metadata,
28    Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
29    Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
30    Column( "user_tname", TrimmedString(255), index=True),
31    Column( "value", TrimmedString(255), index=True),
32    Column( "user_value", TrimmedString(255), index=True) )
33
34def upgrade(migrate_engine):
35    metadata.bind = migrate_engine
36    display_migration_details()
37    metadata.reflect()
38    i = Index( "ix_hda_ta_history_dataset_association_id", HistoryDatasetAssociationTagAssociation_table.c.history_dataset_association_id )
39    try:
40        i.create()
41    except Exception, e:
42        print str(e)
43        log.debug( "Adding index 'ix_hdata_history_dataset_association_id' to table 'history_dataset_association_tag_association' table failed: %s" % str( e ) )
44
45def downgrade(migrate_engine):
46    metadata.bind = migrate_engine
47    metadata.reflect()
48    i = Index( "ix_hda_ta_history_dataset_association_id", HistoryDatasetAssociationTagAssociation_table.c.history_dataset_association_id )
49    try:
50        i.drop()
51    except Exception, e:
52        print str(e)
53        log.debug( "Removing index 'ix_hdata_history_dataset_association_id' to table 'history_dataset_association_tag_association' table failed: %s" % str( e ) )