PageRenderTime 18ms CodeModel.GetById 9ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0040_page_annotations.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 43 lines | 29 code | 9 blank | 5 comment | 0 complexity | 58bc3c29864c1c157e0aaea7bbdbf9da MD5 | raw file
 1"""
 2Migration script to (a) create tables for annotating pages.
 3"""
 4
 5from sqlalchemy import *
 6from sqlalchemy.orm import *
 7from migrate import *
 8from migrate.changeset import *
 9
10import logging
11log = logging.getLogger( __name__ )
12
13metadata = MetaData()
14
15PageAnnotationAssociation_table = Table( "page_annotation_association", metadata,
16    Column( "id", Integer, primary_key=True ),
17    Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ),
18    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
19    Column( "annotation", TEXT, index=True) )
20
21def upgrade(migrate_engine):
22    metadata.bind = migrate_engine
23    print __doc__
24    metadata.reflect()
25
26    # Create history_annotation_association table.
27    try:
28        PageAnnotationAssociation_table.create()
29    except Exception, e:
30        print str(e)
31        log.debug( "Creating page_annotation_association table failed: %s" % str( e ) )
32
33def downgrade(migrate_engine):
34    metadata.bind = migrate_engine
35    metadata.reflect()
36
37    # Drop page_annotation_association table.
38    try:
39        PageAnnotationAssociation_table.drop()
40    except Exception, e:
41       print str(e)
42       log.debug( "Dropping page_annotation_association table failed: %s" % str( e ) )
43