PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0058_history_import_export.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 49 lines | 34 code | 9 blank | 6 comment | 0 complexity | fa374d052a79f2b61e748959e3db39b7 MD5 | raw file
 1"""
 2Migration script to create table for exporting histories to archives.
 3"""
 4
 5from sqlalchemy import *
 6from sqlalchemy.orm import *
 7from migrate import *
 8from migrate.changeset import *
 9
10import logging
11log = logging.getLogger( __name__ )
12
13metadata = MetaData()
14
15# Table to add.
16
17JobExportHistoryArchive_table = Table( "job_export_history_archive", metadata,
18    Column( "id", Integer, primary_key=True ),
19    Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
20    Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
21    Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ),
22    Column( "compressed", Boolean, index=True, default=False ),
23    Column( "history_attrs_filename", TEXT ),
24    Column( "datasets_attrs_filename", TEXT ),
25    Column( "jobs_attrs_filename", TEXT )
26    )
27
28def upgrade(migrate_engine):
29    print __doc__
30    metadata.bind = migrate_engine
31    metadata.reflect()
32
33    # Create job_export_history_archive table.
34    try:
35        JobExportHistoryArchive_table.create()
36    except Exception, e:
37        print str(e)
38        log.debug( "Creating job_export_history_archive table failed: %s" % str( e ) )
39
40def downgrade(migrate_engine):
41    metadata.bind = migrate_engine
42    metadata.reflect()
43
44    # Drop job_export_history_archive table.
45    try:
46        JobExportHistoryArchive_table.drop()
47    except Exception, e:
48        print str(e)
49        log.debug( "Dropping job_export_history_archive table failed: %s" % str( e ) )