root/galaxy-central/lib/galaxy/model/migrate/versions/0042_workflow_invocation_fix.py @ 2

リビジョン 2, 2.2 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1"""
2Drop and readd workflow invocation tables, allowing null jobs
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
17def 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
60def downgrade():
61    # No downgrade
62    pass
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。