root/galaxy-central/lib/galaxy/model/migrate/versions/0048_dataset_instance_state_column.py

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

import galaxy-central

行番号 
1"""
2Add a state column to the history_dataset_association and library_dataset_dataset_association table.
3"""
4
5from sqlalchemy import *
6from sqlalchemy.orm import *
7from sqlalchemy.exc import *
8from migrate import *
9from migrate.changeset import *
10from galaxy.model.custom_types import *
11
12import datetime
13now = datetime.datetime.utcnow
14
15import sys, logging
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( migrate_engine )
25db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )
26
27DATASET_INSTANCE_TABLE_NAMES = [ 'history_dataset_association', 'library_dataset_dataset_association' ]
28
29def upgrade():
30    print __doc__
31    metadata.reflect()
32    dataset_instance_tables = []
33    for table_name in DATASET_INSTANCE_TABLE_NAMES:
34        try:
35            dataset_instance_tables.append( ( table_name, Table( table_name, metadata, autoload=True ) ) )
36        except NoSuchTableError:
37            log.debug( "Failed loading table %s" % table_name )
38    if dataset_instance_tables:
39        for table_name, dataset_instance_table in dataset_instance_tables:
40            try:
41                col = Column( "state", TrimmedString( 64 ), index=True, nullable=True )
42                col.create( dataset_instance_table )
43                assert col is dataset_instance_table.c.state
44            except Exception, e:
45                log.debug( "Adding column 'state' to %s table failed: %s" % ( table_name, str( e ) ) )
46            try:
47                i = Index( "ix_%s_state" % table_name, dataset_instance_table.c.state )
48                i.create()
49            except Exception, e:
50                log.debug( "Adding index 'ix_%s_state' failed: %s" % ( table_name, str( e ) ) )
51def downgrade():
52    metadata.reflect()
53    dataset_instance_tables = []
54    for table_name in DATASET_INSTANCE_TABLE_NAMES:
55        try:
56            dataset_instance_tables.append( ( table_name, Table( table_name, metadata, autoload=True ) ) )
57        except NoSuchTableError:
58            log.debug( "Failed loading table %s" % table_name )
59    if dataset_instance_tables:
60        for table_name, dataset_instance_table in dataset_instance_tables:
61            try:
62                col = dataset_instance_table.c.state
63                col.drop()
64            except Exception, e:
65                log.debug( "Dropping column 'state' from %s table failed: %s" % ( table_name, str( e ) ) )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。