1 | """ |
---|
2 | Migration script to add support for storing visualizations. |
---|
3 | 1) Creates Visualization and VisualizationRevision tables |
---|
4 | """ |
---|
5 | |
---|
6 | from sqlalchemy import * |
---|
7 | from migrate import * |
---|
8 | from migrate.changeset import * |
---|
9 | |
---|
10 | import datetime |
---|
11 | now = datetime.datetime.utcnow |
---|
12 | |
---|
13 | import logging |
---|
14 | log = logging.getLogger( __name__ ) |
---|
15 | |
---|
16 | metadata = MetaData( migrate_engine ) |
---|
17 | |
---|
18 | Visualization_table = Table( "visualization", metadata, |
---|
19 | Column( "id", Integer, primary_key=True ), |
---|
20 | Column( "create_time", DateTime, default=now ), |
---|
21 | Column( "update_time", DateTime, default=now, onupdate=now ), |
---|
22 | Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ), |
---|
23 | Column( "latest_revision_id", Integer, |
---|
24 | ForeignKey( "visualization_revision.id", use_alter=True, name='visualization_latest_revision_id_fk' ), index=True ), |
---|
25 | Column( "title", TEXT ), |
---|
26 | Column( "type", TEXT ) |
---|
27 | ) |
---|
28 | |
---|
29 | VisualizationRevision_table = Table( "visualization_revision", metadata, |
---|
30 | Column( "id", Integer, primary_key=True ), |
---|
31 | Column( "create_time", DateTime, default=now ), |
---|
32 | Column( "update_time", DateTime, default=now, onupdate=now ), |
---|
33 | Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True, nullable=False ), |
---|
34 | Column( "title", TEXT ), |
---|
35 | Column( "config", TEXT ) |
---|
36 | ) |
---|
37 | |
---|
38 | def upgrade(): |
---|
39 | print __doc__ |
---|
40 | metadata.reflect() |
---|
41 | try: |
---|
42 | Visualization_table.create() |
---|
43 | except: |
---|
44 | log.debug( "Could not create page table" ) |
---|
45 | try: |
---|
46 | VisualizationRevision_table.create() |
---|
47 | except: |
---|
48 | log.debug( "Could not create page_revision table" ) |
---|
49 | |
---|
50 | |
---|
51 | def downgrade(): |
---|
52 | metadata.reflect() |
---|
53 | Visualization_table.drop() |
---|
54 | VisualizationRevision_table.drop() |
---|
55 | |
---|