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

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 53 lines · 41 code · 9 blank · 3 comment · 4 complexity · 903c2c08965b0831ba2599b82e5912a0 MD5 · raw file

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