[2] | 1 | """ |
---|
| 2 | This migration script adds a user actions table to Galaxy. |
---|
| 3 | """ |
---|
| 4 | |
---|
| 5 | from sqlalchemy import * |
---|
| 6 | from migrate import * |
---|
| 7 | |
---|
| 8 | import datetime |
---|
| 9 | now = datetime.datetime.utcnow |
---|
| 10 | |
---|
| 11 | import logging |
---|
| 12 | log = logging.getLogger( __name__ ) |
---|
| 13 | |
---|
| 14 | metadata = MetaData( migrate_engine ) |
---|
| 15 | |
---|
| 16 | def 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. |
---|
| 23 | UserAction_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 | |
---|
| 32 | def upgrade(): |
---|
| 33 | display_migration_details() |
---|
| 34 | metadata.reflect() |
---|
| 35 | try: |
---|
| 36 | UserAction_table.create() |
---|
| 37 | except Exception, e: |
---|
| 38 | print str(e) |
---|
| 39 | log.debug( "Creating user_action table failed: %s" % str( e ) ) |
---|
| 40 | |
---|
| 41 | def downgrade(): |
---|
| 42 | metadata.reflect() |
---|
| 43 | try: |
---|
| 44 | UserAction_table.drop() |
---|
| 45 | except Exception, e: |
---|
| 46 | print str(e) |
---|
| 47 | log.debug( "Dropping user_action table failed: %s" % str( e ) ) |
---|