root/galaxy-central/lib/galaxy/model/migrate/versions/0011_v0010_mysql_index_fix.py @ 2

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

import galaxy-central

行番号 
1"""
2This script fixes a problem introduced in 0010_hda_display_at_atuhz_table.py.  MySQL has a
3name length limit and thus the index "ix_hdadaa_history_dataset_association_id" has to be
4manually created.
5"""
6from sqlalchemy import *
7from sqlalchemy.orm import *
8from sqlalchemy.exc import *
9from migrate import *
10from migrate.changeset import *
11
12import datetime
13now = datetime.datetime.utcnow
14
15import sys, logging
16log = logging.getLogger( __name__ )
17log.setLevel(logging.DEBUG)
18handler = logging.StreamHandler( sys.stdout )
19format = "%(name)s %(levelname)s %(asctime)s %(message)s"
20formatter = logging.Formatter( format )
21handler.setFormatter( formatter )
22log.addHandler( handler )
23
24# Need our custom types, but don't import anything else from model
25from galaxy.model.custom_types import *
26
27metadata = MetaData( migrate_engine )
28db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )
29
30def display_migration_details():
31    print "========================================"
32    print "This script fixes a problem introduced in the previous migration script ( 9->10 ).  MySQL"
33    print "has a name length limit and thus the index 'ix_hdadaa_history_dataset_association_id' has"
34    print "to be manually created."
35    print "========================================"
36
37HistoryDatasetAssociationDisplayAtAuthorization_table = Table( "history_dataset_association_display_at_authorization", metadata,
38    Column( "id", Integer, primary_key=True ),
39    Column( "create_time", DateTime, default=now ),
40    Column( "update_time", DateTime, index=True, default=now, onupdate=now ),
41    Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
42    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
43    Column( "site", TrimmedString( 255 ) ) )
44
45def upgrade():
46    display_migration_details()
47    if migrate_engine.name == 'mysql':
48        # Load existing tables
49        metadata.reflect()
50        i = Index( "ix_hdadaa_history_dataset_association_id", HistoryDatasetAssociationDisplayAtAuthorization_table.c.history_dataset_association_id )
51        try:
52            i.create()
53        except Exception, e:
54            log.debug( "Adding index 'ix_hdadaa_history_dataset_association_id' to table 'history_dataset_association_display_at_authorization' table failed: %s" % str( e ) ) 
55
56def downgrade():
57    if migrate_engine.name == 'mysql':
58        # Load existing tables
59        metadata.reflect()
60        i = Index( "ix_hdadaa_history_dataset_association_id", HistoryDatasetAssociationDisplayAtAuthorization_table.c.history_dataset_association_id )
61        try:
62            i.drop()
63        except Exception, e:
64            log.debug( "Removing index 'ix_hdadaa_history_dataset_association_id' from table 'history_dataset_association_display_at_authorization' table failed: %s" % str( e ) ) 
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。