1 | """ |
---|
2 | Migration script to create tables for tracking workflow invocations. |
---|
3 | """ |
---|
4 | |
---|
5 | from sqlalchemy import * |
---|
6 | from sqlalchemy.orm import * |
---|
7 | from migrate import * |
---|
8 | from migrate.changeset import * |
---|
9 | |
---|
10 | import logging |
---|
11 | logging.basicConfig( level=logging.DEBUG ) |
---|
12 | log = logging.getLogger( __name__ ) |
---|
13 | |
---|
14 | import datetime |
---|
15 | now = datetime.datetime.utcnow |
---|
16 | |
---|
17 | metadata = MetaData( migrate_engine ) |
---|
18 | db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) ) |
---|
19 | |
---|
20 | WorkflowInvocation_table = Table( "workflow_invocation", metadata, |
---|
21 | Column( "id", Integer, primary_key=True ), |
---|
22 | Column( "create_time", DateTime, default=now ), |
---|
23 | Column( "update_time", DateTime, default=now, onupdate=now ), |
---|
24 | Column( "workflow_id", Integer, ForeignKey( "workflow.id" ), index=True, nullable=False ) |
---|
25 | ) |
---|
26 | |
---|
27 | WorkflowInvocationStep_table = Table( "workflow_invocation_step", metadata, |
---|
28 | Column( "id", Integer, primary_key=True ), |
---|
29 | Column( "create_time", DateTime, default=now ), |
---|
30 | Column( "update_time", DateTime, default=now, onupdate=now ), |
---|
31 | Column( "workflow_invocation_id", Integer, ForeignKey( "workflow_invocation.id" ), index=True, nullable=False ), |
---|
32 | Column( "workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True, nullable=False ), |
---|
33 | Column( "job_id", Integer, ForeignKey( "job.id" ), index=True, nullable=False ) |
---|
34 | ) |
---|
35 | |
---|
36 | tables = [ WorkflowInvocation_table, WorkflowInvocationStep_table ] |
---|
37 | |
---|
38 | def upgrade(): |
---|
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 | |
---|
48 | def downgrade(): |
---|
49 | metadata.reflect() |
---|
50 | |
---|
51 | for table in tables: |
---|
52 | table.drop() |
---|