PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0061_tasks.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 50 lines | 40 code | 7 blank | 3 comment | 4 complexity | c89a85668187840a6a4de289b20dddf2 MD5 | raw file
 1"""
 2Migration script to create tables task management.
 3"""
 4from sqlalchemy import *
 5from sqlalchemy.orm import *
 6from migrate import *
 7from migrate.changeset import *
 8
 9import datetime
10
11import logging
12log = logging.getLogger( __name__ )
13
14metadata = MetaData()
15now = datetime.datetime.utcnow
16
17Task_table = Table( "task", metadata,
18    Column( "id", Integer, primary_key=True ),
19    Column( "create_time", DateTime, default=now ),
20    Column( "execution_time", DateTime ),
21    Column( "update_time", DateTime, default=now, onupdate=now ),
22    Column( "state", String( 64 ), index=True ),
23    Column( "command_line", TEXT ),
24    Column( "param_filename", String( 1024 ) ),
25    Column( "runner_name", String( 255 ) ),
26    Column( "stdout", TEXT ),
27    Column( "stderr", TEXT ),
28    Column( "traceback", TEXT ),
29    Column( "job_id", Integer, ForeignKey( "job.id" ), index=True, nullable=False ),
30    Column( "part_file", String(1024)),
31    Column( "task_runner_name", String( 255 ) ),
32    Column( "task_runner_external_id", String( 255 ) ) )
33
34tables = [Task_table]
35
36def upgrade(migrate_engine):
37    metadata.bind = migrate_engine
38    print __doc__
39    metadata.reflect()
40    for table in tables:
41        try:
42            table.create()
43        except:
44            log.warn( "Failed to create table '%s', ignoring (might result in wrong schema)" % table.name )
45
46def downgrade(migrate_engine):
47    metadata.bind = migrate_engine
48    metadata.reflect()
49    for table in tables:
50        table.drop()