PageRenderTime 26ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

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