1 | """ |
---|
2 | Migration script to create tables for rating histories, datasets, workflows, pages, and visualizations. |
---|
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 | # Rating tables. |
---|
17 | |
---|
18 | HistoryRatingAssociation_table = Table( "history_rating_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( "rating", Integer, index=True) ) |
---|
23 | |
---|
24 | HistoryDatasetAssociationRatingAssociation_table = Table( "history_dataset_association_rating_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( "rating", Integer, index=True) ) |
---|
29 | |
---|
30 | StoredWorkflowRatingAssociation_table = Table( "stored_workflow_rating_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( "rating", Integer, index=True) ) |
---|
35 | |
---|
36 | PageRatingAssociation_table = Table( "page_rating_association", metadata, |
---|
37 | Column( "id", Integer, primary_key=True ), |
---|
38 | Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ), |
---|
39 | Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), |
---|
40 | Column( "rating", Integer, index=True) ) |
---|
41 | |
---|
42 | VisualizationRatingAssociation_table = Table( "visualization_rating_association", metadata, |
---|
43 | Column( "id", Integer, primary_key=True ), |
---|
44 | Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True ), |
---|
45 | Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), |
---|
46 | Column( "rating", Integer, index=True) ) |
---|
47 | |
---|
48 | def upgrade(): |
---|
49 | print __doc__ |
---|
50 | metadata.reflect() |
---|
51 | |
---|
52 | # Create history_rating_association table. |
---|
53 | try: |
---|
54 | HistoryRatingAssociation_table.create() |
---|
55 | except Exception, e: |
---|
56 | print str(e) |
---|
57 | log.debug( "Creating history_rating_association table failed: %s" % str( e ) ) |
---|
58 | |
---|
59 | # Create history_dataset_association_rating_association table. |
---|
60 | try: |
---|
61 | HistoryDatasetAssociationRatingAssociation_table.create() |
---|
62 | except Exception, e: |
---|
63 | # MySQL cannot handle long index names; when we see this error, create the index name manually. |
---|
64 | if migrate_engine.name == 'mysql' and \ |
---|
65 | str(e).lower().find("identifier name 'ix_history_dataset_association_rating_association_history_dataset_association_id' is too long"): |
---|
66 | i = Index( "ix_hda_rating_association_hda_id", HistoryDatasetAssociationRatingAssociation_table.c.history_dataset_association_id ) |
---|
67 | try: |
---|
68 | i.create() |
---|
69 | except Exception, e: |
---|
70 | print str(e) |
---|
71 | log.debug( "Adding index 'ix_hda_rating_association_hda_id' to table 'history_dataset_association_rating_association' table failed: %s" % str( e ) ) |
---|
72 | else: |
---|
73 | print str(e) |
---|
74 | log.debug( "Creating history_dataset_association_rating_association table failed: %s" % str( e ) ) |
---|
75 | |
---|
76 | # Create stored_workflow_rating_association table. |
---|
77 | try: |
---|
78 | StoredWorkflowRatingAssociation_table.create() |
---|
79 | except Exception, e: |
---|
80 | print str(e) |
---|
81 | log.debug( "Creating stored_workflow_rating_association table failed: %s" % str( e ) ) |
---|
82 | |
---|
83 | # Create page_rating_association table. |
---|
84 | try: |
---|
85 | PageRatingAssociation_table.create() |
---|
86 | except Exception, e: |
---|
87 | print str(e) |
---|
88 | log.debug( "Creating page_rating_association table failed: %s" % str( e ) ) |
---|
89 | |
---|
90 | # Create visualization_rating_association table. |
---|
91 | try: |
---|
92 | VisualizationRatingAssociation_table.create() |
---|
93 | except Exception, e: |
---|
94 | print str(e) |
---|
95 | log.debug( "Creating visualization_rating_association table failed: %s" % str( e ) ) |
---|
96 | |
---|
97 | def downgrade(): |
---|
98 | metadata.reflect() |
---|
99 | |
---|
100 | # Drop history_rating_association table. |
---|
101 | try: |
---|
102 | HistoryRatingAssociation_table.drop() |
---|
103 | except Exception, e: |
---|
104 | print str(e) |
---|
105 | log.debug( "Dropping history_rating_association table failed: %s" % str( e ) ) |
---|
106 | |
---|
107 | # Drop history_dataset_association_rating_association table. |
---|
108 | try: |
---|
109 | HistoryDatasetAssociationRatingAssociation_table.drop() |
---|
110 | except Exception, e: |
---|
111 | print str(e) |
---|
112 | log.debug( "Dropping history_dataset_association_rating_association table failed: %s" % str( e ) ) |
---|
113 | |
---|
114 | # Drop stored_workflow_rating_association table. |
---|
115 | try: |
---|
116 | StoredWorkflowRatingAssociation_table.drop() |
---|
117 | except Exception, e: |
---|
118 | print str(e) |
---|
119 | log.debug( "Dropping stored_workflow_rating_association table failed: %s" % str( e ) ) |
---|
120 | |
---|
121 | # Drop page_rating_association table. |
---|
122 | try: |
---|
123 | PageRatingAssociation_table.drop() |
---|
124 | except Exception, e: |
---|
125 | print str(e) |
---|
126 | log.debug( "Dropping page_rating_association table failed: %s" % str( e ) ) |
---|
127 | |
---|
128 | # Drop visualization_rating_association table. |
---|
129 | try: |
---|
130 | VisualizationRatingAssociation_table.drop() |
---|
131 | except Exception, e: |
---|
132 | print str(e) |
---|
133 | log.debug( "Dropping visualization_rating_association table failed: %s" % str( e ) ) |
---|