1 | """ |
---|
2 | Migration script to (a) create tables for annotating objects and (b) create tags for workflow steps. |
---|
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 | # Annotation tables. |
---|
17 | |
---|
18 | HistoryAnnotationAssociation_table = Table( "history_annotation_association", metadata, |
---|
19 | Column( "id", Integer, primary_key=True ), |
---|
20 | Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ), |
---|
21 | Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), |
---|
22 | Column( "annotation", TEXT, index=True) ) |
---|
23 | |
---|
24 | HistoryDatasetAssociationAnnotationAssociation_table = Table( "history_dataset_association_annotation_association", metadata, |
---|
25 | Column( "id", Integer, primary_key=True ), |
---|
26 | Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ), |
---|
27 | Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), |
---|
28 | Column( "annotation", TEXT, index=True) ) |
---|
29 | |
---|
30 | StoredWorkflowAnnotationAssociation_table = Table( "stored_workflow_annotation_association", metadata, |
---|
31 | Column( "id", Integer, primary_key=True ), |
---|
32 | Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True ), |
---|
33 | Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), |
---|
34 | Column( "annotation", TEXT, index=True) ) |
---|
35 | |
---|
36 | WorkflowStepAnnotationAssociation_table = Table( "workflow_step_annotation_association", metadata, |
---|
37 | Column( "id", Integer, primary_key=True ), |
---|
38 | Column( "workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True ), |
---|
39 | Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), |
---|
40 | Column( "annotation", TEXT, index=True) ) |
---|
41 | |
---|
42 | # Tagging tables. |
---|
43 | |
---|
44 | WorkflowStepTagAssociation_table = Table( "workflow_step_tag_association", metadata, |
---|
45 | Column( "id", Integer, primary_key=True ), |
---|
46 | Column( "workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True ), |
---|
47 | Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ), |
---|
48 | Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), |
---|
49 | Column( "user_tname", Unicode(255), index=True), |
---|
50 | Column( "value", Unicode(255), index=True), |
---|
51 | Column( "user_value", Unicode(255), index=True) ) |
---|
52 | |
---|
53 | def upgrade(): |
---|
54 | print __doc__ |
---|
55 | metadata.reflect() |
---|
56 | |
---|
57 | # Create history_annotation_association table. |
---|
58 | try: |
---|
59 | HistoryAnnotationAssociation_table.create() |
---|
60 | except Exception, e: |
---|
61 | print str(e) |
---|
62 | log.debug( "Creating history_annotation_association table failed: %s" % str( e ) ) |
---|
63 | |
---|
64 | # Create history_dataset_association_annotation_association table. |
---|
65 | try: |
---|
66 | HistoryDatasetAssociationAnnotationAssociation_table.create() |
---|
67 | except Exception, e: |
---|
68 | print str(e) |
---|
69 | log.debug( "Creating history_dataset_association_annotation_association table failed: %s" % str( e ) ) |
---|
70 | |
---|
71 | # Create stored_workflow_annotation_association table. |
---|
72 | try: |
---|
73 | StoredWorkflowAnnotationAssociation_table.create() |
---|
74 | except Exception, e: |
---|
75 | print str(e) |
---|
76 | log.debug( "Creating stored_workflow_annotation_association table failed: %s" % str( e ) ) |
---|
77 | |
---|
78 | # Create workflow_step_annotation_association table. |
---|
79 | try: |
---|
80 | WorkflowStepAnnotationAssociation_table.create() |
---|
81 | except Exception, e: |
---|
82 | print str(e) |
---|
83 | log.debug( "Creating workflow_step_annotation_association table failed: %s" % str( e ) ) |
---|
84 | |
---|
85 | # Create workflow_step_tag_association table. |
---|
86 | try: |
---|
87 | WorkflowStepTagAssociation_table.create() |
---|
88 | except Exception, e: |
---|
89 | print str(e) |
---|
90 | log.debug( "Creating workflow_step_tag_association table failed: %s" % str( e ) ) |
---|
91 | |
---|
92 | def downgrade(): |
---|
93 | metadata.reflect() |
---|
94 | |
---|
95 | # Drop history_annotation_association table. |
---|
96 | try: |
---|
97 | HistoryAnnotationAssociation_table.drop() |
---|
98 | except Exception, e: |
---|
99 | print str(e) |
---|
100 | log.debug( "Dropping history_annotation_association table failed: %s" % str( e ) ) |
---|
101 | |
---|
102 | # Drop history_dataset_association_annotation_association table. |
---|
103 | try: |
---|
104 | HistoryDatasetAssociationAnnotationAssociation_table.drop() |
---|
105 | except Exception, e: |
---|
106 | print str(e) |
---|
107 | log.debug( "Dropping history_dataset_association_annotation_association table failed: %s" % str( e ) ) |
---|
108 | |
---|
109 | # Drop stored_workflow_annotation_association table. |
---|
110 | try: |
---|
111 | StoredWorkflowAnnotationAssociation_table.drop() |
---|
112 | except Exception, e: |
---|
113 | print str(e) |
---|
114 | log.debug( "Dropping stored_workflow_annotation_association table failed: %s" % str( e ) ) |
---|
115 | |
---|
116 | # Drop workflow_step_annotation_association table. |
---|
117 | try: |
---|
118 | WorkflowStepAnnotationAssociation_table.drop() |
---|
119 | except Exception, e: |
---|
120 | print str(e) |
---|
121 | log.debug( "Dropping workflow_step_annotation_association table failed: %s" % str( e ) ) |
---|
122 | |
---|
123 | # Drop workflow_step_tag_association table. |
---|
124 | try: |
---|
125 | WorkflowStepTagAssociation_table.drop() |
---|
126 | except Exception, e: |
---|
127 | print str(e) |
---|
128 | log.debug( "Dropping workflow_step_tag_association table failed: %s" % str( e ) ) |
---|
129 | |
---|