1 | """ |
---|
2 | Migration script to (a) create tables for annotating pages. |
---|
3 | """ |
---|
4 | |
---|
5 | from sqlalchemy import * |
---|
6 | from sqlalchemy.orm import * |
---|
7 | from migrate import * |
---|
8 | from migrate.changeset import * |
---|
9 | |
---|
10 | import logging |
---|
11 | log = logging.getLogger( __name__ ) |
---|
12 | |
---|
13 | metadata = MetaData( migrate_engine ) |
---|
14 | db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) ) |
---|
15 | |
---|
16 | PageAnnotationAssociation_table = Table( "page_annotation_association", metadata, |
---|
17 | Column( "id", Integer, primary_key=True ), |
---|
18 | Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ), |
---|
19 | Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), |
---|
20 | Column( "annotation", TEXT, index=True) ) |
---|
21 | |
---|
22 | def upgrade(): |
---|
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 | |
---|
33 | def downgrade(): |
---|
34 | metadata.reflect() |
---|
35 | |
---|
36 | # Drop page_annotation_association table. |
---|
37 | try: |
---|
38 | PageAnnotationAssociation_table.drop() |
---|
39 | except Exception, e: |
---|
40 | print str(e) |
---|
41 | log.debug( "Dropping page_annotation_association table failed: %s" % str( e ) ) |
---|
42 | |
---|