PageRenderTime 18ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/webapps/community/model/migrate/versions/0003_review_and_review_association_tables.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 51 lines | 39 code | 6 blank | 6 comment | 0 complexity | 9271890b52cb9dbe948605b7fc30faf6 MD5 | raw file
 1"""
 2Adds the tool_rating_association table, enabling tools to be rated along with review comments.
 3"""
 4from sqlalchemy import *
 5from sqlalchemy.orm import *
 6from sqlalchemy.exc import *
 7from migrate import *
 8from migrate.changeset import *
 9
10import datetime
11now = datetime.datetime.utcnow
12
13import sys, logging
14log = logging.getLogger( __name__ )
15log.setLevel(logging.DEBUG)
16handler = logging.StreamHandler( sys.stdout )
17format = "%(name)s %(levelname)s %(asctime)s %(message)s"
18formatter = logging.Formatter( format )
19handler.setFormatter( formatter )
20log.addHandler( handler )
21
22# Need our custom types, but don't import anything else from model
23from galaxy.model.custom_types import *
24
25metadata = MetaData( migrate_engine )
26db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )
27
28ToolRatingAssociation_table = Table( "tool_rating_association", metadata,
29    Column( "id", Integer, primary_key=True ),
30    Column( "create_time", DateTime, default=now ),
31    Column( "update_time", DateTime, default=now, onupdate=now ),
32    Column( "tool_id", Integer, ForeignKey( "tool.id" ), index=True ),
33    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
34    Column( "rating", Integer, index=True ),
35    Column( "comment", TEXT ) )
36
37def upgrade():
38    print __doc__
39    # Load existing tables
40    metadata.reflect()
41    try:
42        ToolRatingAssociation_table.create()
43    except Exception, e:
44        log.debug( "Creating tool_rating_association table failed: %s" % str( e ) )  
45def downgrade():
46    # Load existing tables
47    metadata.reflect()
48    try:
49        ToolRatingAssociation_table.drop()
50    except Exception, e:
51        log.debug( "Dropping tool_rating_association table failed: %s" % str( e ) )