PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0066_deferred_job_and_transfer_job_tables.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 70 lines | 47 code | 14 blank | 9 comment | 0 complexity | c081cd39a8d17f9267c3776706902ee9 MD5 | raw file
 1"""
 2Migration script to create table for storing deferred job and managed transfer
 3information.
 4"""
 5
 6from sqlalchemy import *
 7from sqlalchemy.orm import *
 8from migrate import *
 9from migrate.changeset import *
10
11from galaxy.model.custom_types import *
12
13import datetime
14now = datetime.datetime.utcnow
15
16import logging
17log = logging.getLogger( __name__ )
18
19metadata = MetaData()
20
21# Table to add
22
23DeferredJob_table = Table( "deferred_job", metadata,
24    Column( "id", Integer, primary_key=True ),
25    Column( "create_time", DateTime, default=now ),
26    Column( "update_time", DateTime, default=now, onupdate=now ),
27    Column( "state", String( 64 ), index=True ),
28    Column( "plugin", String( 128 ), index=True ),
29    Column( "params", JSONType ) )
30
31TransferJob_table = Table( "transfer_job", metadata,
32    Column( "id", Integer, primary_key=True ),
33    Column( "create_time", DateTime, default=now ),
34    Column( "update_time", DateTime, default=now, onupdate=now ),
35    Column( "state", String( 64 ), index=True ),
36    Column( "path", String( 1024 ) ),
37    Column( "params", JSONType ) )
38
39def upgrade(migrate_engine):
40    metadata.bind = migrate_engine
41    print __doc__
42    metadata.reflect()
43
44    # Create deferred_job table
45    try:
46        DeferredJob_table.create()
47    except Exception, e:
48        log.error( "Creating deferred_job table failed: %s" % str( e ) )
49
50    # Create transfer_job table
51    try:
52        TransferJob_table.create()
53    except Exception, e:
54        log.error( "Creating transfer_job table failed: %s" % str( e ) )
55
56def downgrade(migrate_engine):
57    metadata.bind = migrate_engine
58    metadata.reflect()
59
60    # Drop deferred_job table
61    try:
62        DeferredJob_table.drop()
63    except Exception, e:
64        log.error( "Dropping deferred_job table failed: %s" % str( e ) )
65
66    # Drop transfer_job table
67    try:
68        TransferJob_table.drop()
69    except Exception, e:
70        log.error( "Dropping transfer_job table failed: %s" % str( e ) )