/lib/galaxy/webapps/community/model/migrate/versions/0006_add_email_alerts_column.py

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 47 lines · 34 code · 6 blank · 7 comment · 4 complexity · 289836d9ba4afee820d7c19c0d03055b MD5 · raw file

  1. """
  2. Migration script to add the email_alerts column to the repository table.
  3. """
  4. from sqlalchemy import *
  5. from sqlalchemy.orm import *
  6. from migrate import *
  7. from migrate.changeset import *
  8. # Need our custom types, but don't import anything else from model
  9. from galaxy.model.custom_types import *
  10. import sys, logging
  11. log = logging.getLogger( __name__ )
  12. log.setLevel(logging.DEBUG)
  13. handler = logging.StreamHandler( sys.stdout )
  14. format = "%(name)s %(levelname)s %(asctime)s %(message)s"
  15. formatter = logging.Formatter( format )
  16. handler.setFormatter( formatter )
  17. log.addHandler( handler )
  18. metadata = MetaData( migrate_engine )
  19. db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )
  20. def upgrade():
  21. print __doc__
  22. metadata.reflect()
  23. # Create and initialize imported column in job table.
  24. Repository_table = Table( "repository", metadata, autoload=True )
  25. c = Column( "email_alerts", JSONType, nullable=True )
  26. try:
  27. # Create
  28. c.create( Repository_table )
  29. assert c is Repository_table.c.email_alerts
  30. except Exception, e:
  31. print "Adding email_alerts column to the repository table failed: %s" % str( e )
  32. log.debug( "Adding email_alerts column to the repository table failed: %s" % str( e ) )
  33. def downgrade():
  34. metadata.reflect()
  35. # Drop email_alerts column from repository table.
  36. Repository_table = Table( "repository", metadata, autoload=True )
  37. try:
  38. Repository_table.c.email_alerts.drop()
  39. except Exception, e:
  40. print "Dropping column email_alerts from the repository table failed: %s" % str( e )
  41. log.debug( "Dropping column email_alerts from the repository table failed: %s" % str( e ) )