PageRenderTime 40ms CodeModel.GetById 32ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0028_external_metadata_file_override.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 48 lines | 36 code | 5 blank | 7 comment | 0 complexity | 661f256c2ab8d7adbb89d51aa4dd1da6 MD5 | raw file
 1"""
 2This script adds the filename_override_metadata column to the JobExternalOutputMetadata table,
 3allowing existing metadata files to be written when using external metadata and a cluster
 4set up with read-only access to database/files
 5"""
 6from sqlalchemy import *
 7from sqlalchemy.orm import *
 8from migrate import *
 9from migrate.changeset import *
10import datetime
11now = datetime.datetime.utcnow
12import sys, logging
13# Need our custom types, but don't import anything else from model
14from galaxy.model.custom_types import *
15
16log = logging.getLogger( __name__ )
17log.setLevel(logging.DEBUG)
18handler = logging.StreamHandler( sys.stdout )
19format = "%(name)s %(levelname)s %(asctime)s %(message)s"
20formatter = logging.Formatter( format )
21handler.setFormatter( formatter )
22log.addHandler( handler )
23
24metadata = MetaData()
25
26def display_migration_details():
27    print "========================================"
28    print "This script adds the filename_override_metadata column to the JobExternalOutputMetadata table,"
29    print" allowing existing metadata files to be written when using external metadata and a cluster"
30    print "set up with read-only access to database/files"
31    print "========================================"
32
33def upgrade(migrate_engine):
34    metadata.bind = migrate_engine
35    display_migration_details()
36    # Load existing tables
37    metadata.reflect()
38    try:
39        job_external_output_metadata = Table( "job_external_output_metadata", metadata, autoload=True )
40        col = Column( "filename_override_metadata", String( 255 ) )
41        col.create( job_external_output_metadata )
42        assert col is job_external_output_metadata.c.filename_override_metadata
43    except Exception, e:
44        log.debug( "Adding column 'filename_override_metadata' to job_external_output_metadata table failed: %s" % ( str( e ) ) )
45
46def downgrade(migrate_engine):
47    metadata.bind = migrate_engine
48    pass