root/galaxy-central/lib/galaxy/model/migrate/versions/0016_v0015_mysql_index_fix.py

リビジョン 2, 2.0 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
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( migrate_engine )
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():
35    display_migration_details()
36    metadata.reflect()
37    i = Index( "ix_hda_ta_history_dataset_association_id", HistoryDatasetAssociationTagAssociation_table.c.history_dataset_association_id )
38    try:
39        i.create()
40    except Exception, e:
41        print str(e)
42        log.debug( "Adding index 'ix_hdata_history_dataset_association_id' to table 'history_dataset_association_tag_association' table failed: %s" % str( e ) )
43   
44def downgrade():
45    metadata.reflect()
46    i = Index( "ix_hda_ta_history_dataset_association_id", HistoryDatasetAssociationTagAssociation_table.c.history_dataset_association_id )
47    try:
48        i.drop()
49    except Exception, e:
50        print str(e)
51        log.debug( "Removing index 'ix_hdata_history_dataset_association_id' to table 'history_dataset_association_tag_association' table failed: %s" % str( e ) )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。