root/galaxy-central/lib/galaxy/model/migrate/versions/0006_change_qual_datatype.py @ 2

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

import galaxy-central

行番号 
1"""
2This migration script changes certain values in the history_dataset_association.extension
3column, specifically 'qual' is chaged to be 'qual454'.
4"""
5from sqlalchemy import *
6from sqlalchemy.orm import *
7from migrate import *
8import sys, logging
9
10log = logging.getLogger( __name__ )
11log.setLevel(logging.DEBUG)
12handler = logging.StreamHandler( sys.stdout )
13format = "%(name)s %(levelname)s %(asctime)s %(message)s"
14formatter = logging.Formatter( format )
15handler.setFormatter( formatter )
16log.addHandler( handler )
17
18metadata = MetaData( migrate_engine )
19db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )
20
21def display_migration_details():
22    print "========================================"
23    print "This migration script changes certain values in the history_dataset_association.extension"
24    print "column, specifically 'qual' is chaged to be 'qual454'."
25    print "========================================"
26
27HistoryDatasetAssociation_table = Table( "history_dataset_association", metadata, autoload=True )
28
29def upgrade():
30    display_migration_details()
31    # Load existing tables
32    metadata.reflect()
33    # Add 2 indexes to the galaxy_user table
34    i = Index( 'ix_hda_extension', HistoryDatasetAssociation_table.c.extension )
35    try:
36        i.create()
37    except Exception, e:
38        log.debug( "Adding index 'ix_hda_extension' to history_dataset_association table failed: %s" % ( str( e ) ) )
39
40    # Set the default data in the galaxy_user table, but only for null values
41    cmd = "UPDATE history_dataset_association SET extension = 'qual454' WHERE extension = 'qual' and peek like \'>%%\'"
42    try:
43        db_session.execute( cmd )
44    except Exception, e:
45        log.debug( "Resetting extension qual to qual454 in history_dataset_association failed: %s" % ( str( e ) ) )
46    cmd = "UPDATE history_dataset_association SET extension = 'qualsolexa' WHERE extension = 'qual' and peek not like \'>%%\'"
47    try:
48        db_session.execute( cmd )
49    except Exception, e:
50        log.debug( "Resetting extension qual to qualsolexa in history_dataset_association failed: %s" % ( str( e ) ) )
51    # Add 1 index to the history_dataset_association table
52    try:
53        i.drop()
54    except Exception, e:
55        log.debug( "Dropping index 'ix_hda_extension' to history_dataset_association table failed: %s" % ( str( e ) ) )
56
57def downgrade():
58    pass
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。