[2] | 1 | """ |
---|
| 2 | This script fixes a problem introduced in 0010_hda_display_at_atuhz_table.py. MySQL has a |
---|
| 3 | name length limit and thus the index "ix_hdadaa_history_dataset_association_id" has to be |
---|
| 4 | manually created. |
---|
| 5 | """ |
---|
| 6 | from sqlalchemy import * |
---|
| 7 | from sqlalchemy.orm import * |
---|
| 8 | from sqlalchemy.exc import * |
---|
| 9 | from migrate import * |
---|
| 10 | from migrate.changeset import * |
---|
| 11 | |
---|
| 12 | import datetime |
---|
| 13 | now = datetime.datetime.utcnow |
---|
| 14 | |
---|
| 15 | import sys, logging |
---|
| 16 | log = logging.getLogger( __name__ ) |
---|
| 17 | log.setLevel(logging.DEBUG) |
---|
| 18 | handler = logging.StreamHandler( sys.stdout ) |
---|
| 19 | format = "%(name)s %(levelname)s %(asctime)s %(message)s" |
---|
| 20 | formatter = logging.Formatter( format ) |
---|
| 21 | handler.setFormatter( formatter ) |
---|
| 22 | log.addHandler( handler ) |
---|
| 23 | |
---|
| 24 | # Need our custom types, but don't import anything else from model |
---|
| 25 | from galaxy.model.custom_types import * |
---|
| 26 | |
---|
| 27 | metadata = MetaData( migrate_engine ) |
---|
| 28 | db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) ) |
---|
| 29 | |
---|
| 30 | def 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 | |
---|
| 37 | HistoryDatasetAssociationDisplayAtAuthorization_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 | |
---|
| 45 | def 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 | |
---|
| 56 | def 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 ) ) |
---|