1 | """ |
---|
2 | Drop and readd workflow invocation tables, allowing null jobs |
---|
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 | def upgrade(): |
---|
18 | print __doc__ |
---|
19 | |
---|
20 | metadata = MetaData( migrate_engine ) |
---|
21 | db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) ) |
---|
22 | metadata.reflect() |
---|
23 | |
---|
24 | # 1) Drop |
---|
25 | |
---|
26 | for table_name in [ "workflow_invocation_step", "workflow_invocation" ]: |
---|
27 | try: |
---|
28 | t = Table( table_name, metadata, autoload=True ).drop() |
---|
29 | except: |
---|
30 | log.exception( "Failed to drop table '%s', ignoring (might result in wrong schema)" % table_name ) |
---|
31 | |
---|
32 | # 2) Readd |
---|
33 | |
---|
34 | metadata = MetaData( migrate_engine ) |
---|
35 | db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) ) |
---|
36 | metadata.reflect() |
---|
37 | |
---|
38 | WorkflowInvocation_table = Table( "workflow_invocation", metadata, |
---|
39 | Column( "id", Integer, primary_key=True ), |
---|
40 | Column( "create_time", DateTime, default=now ), |
---|
41 | Column( "update_time", DateTime, default=now, onupdate=now ), |
---|
42 | Column( "workflow_id", Integer, ForeignKey( "workflow.id" ), index=True, nullable=False ), |
---|
43 | ) |
---|
44 | |
---|
45 | WorkflowInvocationStep_table = Table( "workflow_invocation_step", metadata, |
---|
46 | Column( "id", Integer, primary_key=True ), |
---|
47 | Column( "create_time", DateTime, default=now ), |
---|
48 | Column( "update_time", DateTime, default=now, onupdate=now ), |
---|
49 | Column( "workflow_invocation_id", Integer, ForeignKey( "workflow_invocation.id" ), index=True, nullable=False ), |
---|
50 | Column( "workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True, nullable=False ), |
---|
51 | Column( "job_id", Integer, ForeignKey( "job.id" ), index=True, nullable=True ), |
---|
52 | ) |
---|
53 | |
---|
54 | for table in [ WorkflowInvocation_table, WorkflowInvocationStep_table ]: |
---|
55 | try: |
---|
56 | table.create() |
---|
57 | except: |
---|
58 | log.exception( "Failed to create table '%s', ignoring (might result in wrong schema)" % table.name ) |
---|
59 | |
---|
60 | def downgrade(): |
---|
61 | # No downgrade |
---|
62 | pass |
---|