PageRenderTime 19ms CodeModel.GetById 9ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0029_user_actions.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 49 lines | 41 code | 5 blank | 3 comment | 0 complexity | 1ab38ba63f7671f00aef2f8a4dfa2123 MD5 | raw file
 1"""
 2This migration script adds a user actions table to Galaxy.
 3"""
 4
 5from sqlalchemy import *
 6from migrate import *
 7
 8import datetime
 9now = datetime.datetime.utcnow
10
11import logging
12log = logging.getLogger( __name__ )
13
14metadata = MetaData()
15
16def display_migration_details():
17    print ""
18    print "This migration script adds a user actions table to Galaxy."
19    print ""
20
21
22# New table to store user actions.
23UserAction_table = Table( "user_action", metadata,
24    Column( "id", Integer, primary_key=True ),
25    Column( "create_time", DateTime, default=now ),
26    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
27    Column( "session_id", Integer, ForeignKey( "galaxy_session.id" ), index=True ),
28    Column( "action", Unicode( 255 ) ),
29    Column( "context", Unicode( 512 ) ),
30    Column( "params", Unicode( 1024 ) ) )
31
32def upgrade(migrate_engine):
33    metadata.bind = migrate_engine
34    display_migration_details()
35    metadata.reflect()
36    try:
37        UserAction_table.create()
38    except Exception, e:
39        print str(e)
40        log.debug( "Creating user_action table failed: %s" % str( e ) )
41
42def downgrade(migrate_engine):
43    metadata.bind = migrate_engine
44    metadata.reflect()
45    try:
46        UserAction_table.drop()
47    except Exception, e:
48        print str(e)
49        log.debug( "Dropping user_action table failed: %s" % str( e ) )