PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0041_workflow_invocation.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 53 lines | 39 code | 11 blank | 3 comment | 4 complexity | 895495b098b8e969568691db1aefe0f2 MD5 | raw file
 1"""
 2Migration script to create tables for tracking workflow invocations.
 3"""
 4
 5from sqlalchemy import *
 6from sqlalchemy.orm import *
 7from migrate import *
 8from migrate.changeset import *
 9
10import logging
11logging.basicConfig( level=logging.DEBUG )
12log = logging.getLogger( __name__ )
13
14import datetime
15now = datetime.datetime.utcnow
16
17metadata = MetaData()
18
19WorkflowInvocation_table = Table( "workflow_invocation", metadata,
20    Column( "id", Integer, primary_key=True ),
21    Column( "create_time", DateTime, default=now ),
22    Column( "update_time", DateTime, default=now, onupdate=now ),
23    Column( "workflow_id", Integer, ForeignKey( "workflow.id" ), index=True, nullable=False )
24    )
25
26WorkflowInvocationStep_table = Table( "workflow_invocation_step", metadata,
27    Column( "id", Integer, primary_key=True ),
28    Column( "create_time", DateTime, default=now ),
29    Column( "update_time", DateTime, default=now, onupdate=now ),
30    Column( "workflow_invocation_id", Integer, ForeignKey( "workflow_invocation.id" ), index=True, nullable=False ),
31    Column( "workflow_step_id",  Integer, ForeignKey( "workflow_step.id" ), index=True, nullable=False ),
32    Column( "job_id",  Integer, ForeignKey( "job.id" ), index=True, nullable=False )
33    )
34
35tables = [ WorkflowInvocation_table, WorkflowInvocationStep_table ]
36
37def upgrade(migrate_engine):
38    metadata.bind = migrate_engine
39    print __doc__
40    metadata.reflect()
41
42    for table in tables:
43        try:
44            table.create()
45        except:
46            log.warn( "Failed to create table '%s', ignoring (might result in wrong schema)" % table.name )
47
48def downgrade(migrate_engine):
49    metadata.bind = migrate_engine
50    metadata.reflect()
51
52    for table in tables:
53        table.drop()