/lib/galaxy/model/migrate/versions/0073_add_ldda_to_implicit_conversion_table.py

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 40 lines · 38 code · 1 blank · 1 comment · 3 complexity · 2f2a1f9317e6baf28b2fd29bb0d80d1b MD5 · raw file

  1. """
  2. Migration script to add 'ldda_parent_id' column to the implicitly_converted_dataset_association table.
  3. """
  4. from sqlalchemy import *
  5. from sqlalchemy.orm import *
  6. from migrate import *
  7. from migrate.changeset import *
  8. import logging
  9. log = logging.getLogger( __name__ )
  10. metadata = MetaData()
  11. def upgrade(migrate_engine):
  12. metadata.bind = migrate_engine
  13. print __doc__
  14. metadata.reflect()
  15. try:
  16. Implicitly_converted_table = Table( "implicitly_converted_dataset_association", metadata, autoload=True )
  17. if migrate_engine.name != 'sqlite':
  18. c = Column( "ldda_parent_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), index=True, nullable=True )
  19. else:
  20. #Can't use the ForeignKey in sqlite.
  21. c = Column( "ldda_parent_id", Integer, index=True, nullable=True )
  22. c.create( Implicitly_converted_table, index_name="ix_implicitly_converted_dataset_assoc_ldda_parent_id")
  23. assert c is Implicitly_converted_table.c.ldda_parent_id
  24. except Exception, e:
  25. print "Adding ldda_parent_id column to implicitly_converted_dataset_association table failed: %s" % str( e )
  26. log.debug( "Adding ldda_parent_id column to implicitly_converted_dataset_association table failed: %s" % str( e ) )
  27. def downgrade(migrate_engine):
  28. metadata.bind = migrate_engine
  29. metadata.reflect()
  30. try:
  31. Implicitly_converted_table = Table( "implicitly_converted_dataset_association", metadata, autoload=True )
  32. Implicitly_converted_table.c.ldda_parent_id.drop()
  33. except Exception, e:
  34. print "Dropping ldda_parent_id column from implicitly_converted_dataset_association table failed: %s" % str( e )
  35. log.debug( "Dropping ldda_parent_id column from implicitly_converted_dataset_association table failed: %s" % str( e ) )