[2] | 1 | """ |
---|
| 2 | This migration script adds the tables necessary to support tagging of histories, |
---|
| 3 | datasets, and history-dataset associations (user views of datasets). |
---|
| 4 | |
---|
| 5 | If using mysql, this script will display the following error, which is corrected in the next |
---|
| 6 | migration script: |
---|
| 7 | |
---|
| 8 | history_dataset_association_tag_association table failed: (OperationalError) |
---|
| 9 | (1059, "Identifier name 'ix_history_dataset_association_tag_association_history_dataset_association_id' |
---|
| 10 | is too long) |
---|
| 11 | """ |
---|
| 12 | |
---|
| 13 | from sqlalchemy import * |
---|
| 14 | from migrate import * |
---|
| 15 | |
---|
| 16 | import datetime |
---|
| 17 | now = datetime.datetime.utcnow |
---|
| 18 | |
---|
| 19 | # Need our custom types, but don't import anything else from model |
---|
| 20 | from galaxy.model.custom_types import * |
---|
| 21 | |
---|
| 22 | import logging |
---|
| 23 | log = logging.getLogger( __name__ ) |
---|
| 24 | |
---|
| 25 | metadata = MetaData( migrate_engine ) |
---|
| 26 | |
---|
| 27 | def display_migration_details(): |
---|
| 28 | print "" |
---|
| 29 | print "This migration script adds the tables necessary to support tagging of histories," |
---|
| 30 | print "datasets, and history-dataset associations (user views of datasets)." |
---|
| 31 | print "" |
---|
| 32 | print "If using mysql, this script will display the following error, which is " |
---|
| 33 | print "corrected in the next migration script:" |
---|
| 34 | print "history_dataset_association_tag_association table failed: " |
---|
| 35 | print "(OperationalError) (1059, 'Identifier name " |
---|
| 36 | print "'ix_history_dataset_association_tag_association_history_dataset_association_id'" |
---|
| 37 | print "is too long)" |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | # New tables to support tagging of histories, datasets, and history-dataset associations. |
---|
| 41 | Tag_table = Table( "tag", metadata, |
---|
| 42 | Column( "id", Integer, primary_key=True ), |
---|
| 43 | Column( "type", Integer ), |
---|
| 44 | Column( "parent_id", Integer, ForeignKey( "tag.id" ) ), |
---|
| 45 | Column( "name", TrimmedString(255) ), |
---|
| 46 | UniqueConstraint( "name" ) ) |
---|
| 47 | |
---|
| 48 | HistoryTagAssociation_table = Table( "history_tag_association", metadata, |
---|
| 49 | Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ), |
---|
| 50 | Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), |
---|
| 51 | Column( "user_tname", TrimmedString(255), index=True), |
---|
| 52 | Column( "value", TrimmedString(255), index=True), |
---|
| 53 | Column( "user_value", TrimmedString(255), index=True) ) |
---|
| 54 | |
---|
| 55 | DatasetTagAssociation_table = Table( "dataset_tag_association", metadata, |
---|
| 56 | Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ), |
---|
| 57 | Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), |
---|
| 58 | Column( "user_tname", TrimmedString(255), index=True), |
---|
| 59 | Column( "value", TrimmedString(255), index=True), |
---|
| 60 | Column( "user_value", TrimmedString(255), index=True) ) |
---|
| 61 | |
---|
| 62 | HistoryDatasetAssociationTagAssociation_table = Table( "history_dataset_association_tag_association", metadata, |
---|
| 63 | Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ), |
---|
| 64 | Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), |
---|
| 65 | Column( "user_tname", TrimmedString(255), index=True), |
---|
| 66 | Column( "value", TrimmedString(255), index=True), |
---|
| 67 | Column( "user_value", TrimmedString(255), index=True) ) |
---|
| 68 | |
---|
| 69 | def upgrade(): |
---|
| 70 | display_migration_details() |
---|
| 71 | metadata.reflect() |
---|
| 72 | try: |
---|
| 73 | Tag_table.create() |
---|
| 74 | except Exception, e: |
---|
| 75 | print str(e) |
---|
| 76 | log.debug( "Creating tag table failed: %s" % str( e ) ) |
---|
| 77 | try: |
---|
| 78 | HistoryTagAssociation_table.create() |
---|
| 79 | except Exception, e: |
---|
| 80 | print str(e) |
---|
| 81 | log.debug( "Creating history_tag_association table failed: %s" % str( e ) ) |
---|
| 82 | try: |
---|
| 83 | DatasetTagAssociation_table.create() |
---|
| 84 | except Exception, e: |
---|
| 85 | print str(e) |
---|
| 86 | log.debug( "Creating dataset_tag_association table failed: %s" % str( e ) ) |
---|
| 87 | try: |
---|
| 88 | HistoryDatasetAssociationTagAssociation_table.create() |
---|
| 89 | except Exception, e: |
---|
| 90 | print str(e) |
---|
| 91 | log.debug( "Creating history_dataset_association_tag_association table failed: %s" % str( e ) ) |
---|
| 92 | |
---|
| 93 | def downgrade(): |
---|
| 94 | metadata.reflect() |
---|
| 95 | try: |
---|
| 96 | Tag_table.drop() |
---|
| 97 | except Exception, e: |
---|
| 98 | print str(e) |
---|
| 99 | log.debug( "Dropping tag table failed: %s" % str( e ) ) |
---|
| 100 | try: |
---|
| 101 | HistoryTagAssociation_table.drop() |
---|
| 102 | except Exception, e: |
---|
| 103 | print str(e) |
---|
| 104 | log.debug( "Dropping history_tag_association table failed: %s" % str( e ) ) |
---|
| 105 | try: |
---|
| 106 | DatasetTagAssociation_table.drop() |
---|
| 107 | except Exception, e: |
---|
| 108 | print str(e) |
---|
| 109 | log.debug( "Dropping dataset_tag_association table failed: %s" % str( e ) ) |
---|
| 110 | try: |
---|
| 111 | HistoryDatasetAssociationTagAssociation_table.drop() |
---|
| 112 | except Exception, e: |
---|
| 113 | print str(e) |
---|
| 114 | log.debug( "Dropping history_dataset_association_tag_association table failed: %s" % str( e ) ) |
---|