/lib/galaxy/model/migrate/versions/0006_change_qual_datatype.py

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 60 lines · 58 code · 0 blank · 2 comment · 0 complexity · a7ce98a167ab3caaee879f6bf8850fdc MD5 · raw file

  1. """
  2. This migration script changes certain values in the history_dataset_association.extension
  3. column, specifically 'qual' is chaged to be 'qual454'.
  4. """
  5. from sqlalchemy import *
  6. from sqlalchemy.orm import *
  7. from migrate import *
  8. import sys, logging
  9. log = logging.getLogger( __name__ )
  10. log.setLevel(logging.DEBUG)
  11. handler = logging.StreamHandler( sys.stdout )
  12. format = "%(name)s %(levelname)s %(asctime)s %(message)s"
  13. formatter = logging.Formatter( format )
  14. handler.setFormatter( formatter )
  15. log.addHandler( handler )
  16. metadata = MetaData()
  17. def display_migration_details():
  18. print "========================================"
  19. print "This migration script changes certain values in the history_dataset_association.extension"
  20. print "column, specifically 'qual' is chaged to be 'qual454'."
  21. print "========================================"
  22. def upgrade(migrate_engine):
  23. display_migration_details()
  24. metadata.bind = migrate_engine
  25. db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )
  26. HistoryDatasetAssociation_table = Table( "history_dataset_association", metadata, autoload=True )
  27. # Load existing tables
  28. metadata.reflect()
  29. # Add 2 indexes to the galaxy_user table
  30. i = Index( 'ix_hda_extension', HistoryDatasetAssociation_table.c.extension )
  31. try:
  32. i.create()
  33. except Exception, e:
  34. log.debug( "Adding index 'ix_hda_extension' to history_dataset_association table failed: %s" % ( str( e ) ) )
  35. # Set the default data in the galaxy_user table, but only for null values
  36. cmd = "UPDATE history_dataset_association SET extension = 'qual454' WHERE extension = 'qual' and peek like \'>%%\'"
  37. try:
  38. db_session.execute( cmd )
  39. except Exception, e:
  40. log.debug( "Resetting extension qual to qual454 in history_dataset_association failed: %s" % ( str( e ) ) )
  41. cmd = "UPDATE history_dataset_association SET extension = 'qualsolexa' WHERE extension = 'qual' and peek not like \'>%%\'"
  42. try:
  43. db_session.execute( cmd )
  44. except Exception, e:
  45. log.debug( "Resetting extension qual to qualsolexa in history_dataset_association failed: %s" % ( str( e ) ) )
  46. # Add 1 index to the history_dataset_association table
  47. try:
  48. i.drop()
  49. except Exception, e:
  50. log.debug( "Dropping index 'ix_hda_extension' to history_dataset_association table failed: %s" % ( str( e ) ) )
  51. def downgrade(migrate_engine):
  52. metadata.bind = migrate_engine
  53. pass