PageRenderTime 30ms CodeModel.GetById 11ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/galaxy/webapps/community/model/migrate/versions/0005_drop_tool_related_tables.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 193 lines | 157 code | 12 blank | 24 comment | 0 complexity | 7bbecc7a72f857804919ed953161c37a MD5 | raw file
  1"""
  2Drops the tool, tool_category_association, event, tool_event_association, tool_rating_association,
  3tool_tag_association and tool_annotation_association tables since they are no longer used in the 
  4next-gen tool shed.
  5"""
  6from sqlalchemy import *
  7from sqlalchemy.orm import *
  8from sqlalchemy.exc import *
  9from migrate import *
 10from migrate.changeset import *
 11
 12import datetime
 13now = datetime.datetime.utcnow
 14
 15import sys, logging
 16log = logging.getLogger( __name__ )
 17log.setLevel( logging.DEBUG )
 18handler = logging.StreamHandler( sys.stdout )
 19format = "%(name)s %(levelname)s %(asctime)s %(message)s"
 20formatter = logging.Formatter( format )
 21handler.setFormatter( formatter )
 22log.addHandler( handler )
 23
 24# Need our custom types, but don't import anything else from model
 25from galaxy.model.custom_types import *
 26
 27metadata = MetaData( migrate_engine )
 28db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )
 29
 30def upgrade():
 31    print __doc__
 32    # Load existing tables
 33    metadata.reflect()
 34    # Load and then drop the tool_category_association table
 35    try:
 36        ToolCategoryAssociation_table = Table( "tool_category_association", metadata, autoload=True )
 37    except NoSuchTableError:
 38        log.debug( "Failed loading table tool_category_association" )
 39    try:
 40        ToolCategoryAssociation_table.drop()
 41    except Exception, e:
 42        log.debug( "Dropping tool_category_association table failed: %s" % str( e ) )
 43    # Load and then drop the tool_event_association table
 44    try:
 45        ToolEventAssociation_table = Table( "tool_event_association", metadata, autoload=True )
 46    except NoSuchTableError:
 47        log.debug( "Failed loading table tool_event_association" )
 48    try:
 49        ToolEventAssociation_table.drop()
 50    except Exception, e:
 51        log.debug( "Dropping tool_event_association table failed: %s" % str( e ) )
 52    # Load and then drop the tool_rating_association table
 53    try:
 54        ToolRatingAssociation_table = Table( "tool_rating_association", metadata, autoload=True )
 55    except NoSuchTableError:
 56        log.debug( "Failed loading table tool_rating_association" )
 57    try:
 58        ToolRatingAssociation_table.drop()
 59    except Exception, e:
 60        log.debug( "Dropping tool_rating_association table failed: %s" % str( e ) )
 61    # Load and then drop the tool_tag_association table
 62    try:
 63        ToolTagAssociation_table = Table( "tool_tag_association", metadata, autoload=True )
 64    except NoSuchTableError:
 65        log.debug( "Failed loading table tool_tag_association" )
 66    try:
 67        ToolTagAssociation_table.drop()
 68    except Exception, e:
 69        log.debug( "Dropping tool_tag_association table failed: %s" % str( e ) )
 70    # Load and then drop the tool_annotation_association table
 71    try:
 72        ToolAnnotationAssociation_table = Table( "tool_annotation_association", metadata, autoload=True )
 73    except NoSuchTableError:
 74        log.debug( "Failed loading table tool_annotation_association" )
 75    try:
 76        ToolAnnotationAssociation_table.drop()
 77    except Exception, e:
 78        log.debug( "Dropping tool_annotation_association table failed: %s" % str( e ) )
 79    # Load and then drop the event table
 80    try:
 81        Event_table = Table( "event", metadata, autoload=True )
 82    except NoSuchTableError:
 83        log.debug( "Failed loading table event" )
 84    try:
 85        Event_table.drop()
 86    except Exception, e:
 87        log.debug( "Dropping event table failed: %s" % str( e ) )
 88    # Load and then drop the tool table
 89    try:
 90        Tool_table = Table( "tool", metadata, autoload=True )
 91    except NoSuchTableError:
 92        log.debug( "Failed loading table tool" )
 93    try:
 94        Tool_table.drop()
 95    except Exception, e:
 96        log.debug( "Dropping tool table failed: %s" % str( e ) )
 97def downgrade():
 98    # Load existing tables
 99    metadata.reflect()
100    # We've lost all of our data, so downgrading is useless. However, we'll
101    # at least re-create the dropped tables.
102    Event_table = Table( 'event', metadata,
103        Column( "id", Integer, primary_key=True ),
104        Column( "create_time", DateTime, default=now ),
105        Column( "update_time", DateTime, default=now, onupdate=now ),
106        Column( "state", TrimmedString( 255 ), index=True ),
107        Column( "comment", TEXT ) )
108
109    Tool_table = Table( "tool", metadata, 
110        Column( "id", Integer, primary_key=True ),
111        Column( "guid", TrimmedString( 255 ), index=True, unique=True ),
112        Column( "tool_id", TrimmedString( 255 ), index=True ),
113        Column( "create_time", DateTime, default=now ),
114        Column( "update_time", DateTime, default=now, onupdate=now ),
115        Column( "newer_version_id", Integer, ForeignKey( "tool.id" ), nullable=True ),
116        Column( "name", TrimmedString( 255 ), index=True ),
117        Column( "description" , TEXT ),
118        Column( "user_description" , TEXT ),
119        Column( "version", TrimmedString( 255 ) ),
120        Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
121        Column( "external_filename" , TEXT ),
122        Column( "deleted", Boolean, index=True, default=False ),
123        Column( "suite", Boolean, default=False, index=True ) )
124
125    ToolCategoryAssociation_table = Table( "tool_category_association", metadata,
126        Column( "id", Integer, primary_key=True ),
127        Column( "tool_id", Integer, ForeignKey( "tool.id" ), index=True ),
128        Column( "category_id", Integer, ForeignKey( "category.id" ), index=True ) )
129
130    ToolEventAssociation_table = Table( "tool_event_association", metadata,
131        Column( "id", Integer, primary_key=True ),
132        Column( "tool_id", Integer, ForeignKey( "tool.id" ), index=True ),
133        Column( "event_id", Integer, ForeignKey( "event.id" ), index=True ) )
134
135    ToolRatingAssociation_table = Table( "tool_rating_association", metadata,
136        Column( "id", Integer, primary_key=True ),
137        Column( "create_time", DateTime, default=now ),
138        Column( "update_time", DateTime, default=now, onupdate=now ),
139        Column( "tool_id", Integer, ForeignKey( "tool.id" ), index=True ),
140        Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
141        Column( "rating", Integer, index=True ),
142        Column( "comment", TEXT ) )
143
144    ToolTagAssociation_table = Table( "tool_tag_association", metadata,
145        Column( "id", Integer, primary_key=True ),
146        Column( "tool_id", Integer, ForeignKey( "tool.id" ), index=True ),
147        Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
148        Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
149        Column( "user_tname", TrimmedString(255), index=True),
150        Column( "value", TrimmedString(255), index=True),
151        Column( "user_value", TrimmedString(255), index=True) )
152
153    ToolAnnotationAssociation_table = Table( "tool_annotation_association", metadata,
154        Column( "id", Integer, primary_key=True ),
155        Column( "tool_id", Integer, ForeignKey( "tool.id" ), index=True ),
156        Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
157        Column( "annotation", TEXT, index=True) )
158
159    # Create the event table
160    try:
161        Event_table.create()
162    except Exception, e:
163        log.debug( "Creating event table failed: %s" % str( e ) )
164    # Create the tool table
165    try:
166        Tool_table.create()
167    except Exception, e:
168        log.debug( "Creating tool table failed: %s" % str( e ) )
169    # Create the tool_category_association table
170    try:
171        ToolCategoryAssociation_table.create()
172    except Exception, e:
173        log.debug( "Creating tool_category_association table failed: %s" % str( e ) )
174    # Create the tool_event_association table
175    try:
176        ToolEventAssociation_table.create()
177    except Exception, e:
178        log.debug( "Creating tool_event_association table failed: %s" % str( e ) )
179    # Create the tool_rating_association table
180    try:
181        ToolRatingAssociation_table.create()
182    except Exception, e:
183        log.debug( "Creating tool_rating_association table failed: %s" % str( e ) )
184    # Create the tool_tag_association table
185    try:
186        ToolTagAssociation_table.create()
187    except Exception, e:
188        log.debug( "Creating tool_tag_association table failed: %s" % str( e ) )
189    # Create the tool_annotation_association table
190    try:
191        ToolAnnotationAssociation_table.create()
192    except Exception, e:
193        log.debug( "Creating tool_annotation_association table failed: %s" % str( e ) )