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

/lib/galaxy/model/migrate/versions/0045_request_type_permissions_table.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 36 lines | 26 code | 7 blank | 3 comment | 0 complexity | adb66822354f639b36e96e4ebe5b5171 MD5 | raw file
 1"""
 2Migration script to add the request_type_permissions table.
 3"""
 4
 5from sqlalchemy import *
 6from migrate import *
 7from migrate.changeset import *
 8
 9import datetime
10now = datetime.datetime.utcnow
11
12import logging
13log = logging.getLogger( __name__ )
14
15metadata = MetaData()
16
17RequestTypePermissions_table = Table( "request_type_permissions", metadata,
18    Column( "id", Integer, primary_key=True ),
19    Column( "create_time", DateTime, default=now ),
20    Column( "update_time", DateTime, default=now, onupdate=now ),
21    Column( "action", TEXT ),
22    Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), nullable=True, index=True ),
23    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
24
25def upgrade(migrate_engine):
26    metadata.bind = migrate_engine
27    print __doc__
28    metadata.reflect()
29    try:
30        RequestTypePermissions_table.create()
31    except Exception, e:
32        log.debug( "Creating request_type_permissions table failed: %s" % str( e ) )
33
34def downgrade(migrate_engine):
35    metadata.bind = migrate_engine
36    pass