1 | """ |
---|
2 | This migration script changes certain values in the history_dataset_association.extension |
---|
3 | column, specifically 'qual' is chaged to be 'qual454'. |
---|
4 | """ |
---|
5 | from sqlalchemy import * |
---|
6 | from sqlalchemy.orm import * |
---|
7 | from migrate import * |
---|
8 | import sys, logging |
---|
9 | |
---|
10 | log = logging.getLogger( __name__ ) |
---|
11 | log.setLevel(logging.DEBUG) |
---|
12 | handler = logging.StreamHandler( sys.stdout ) |
---|
13 | format = "%(name)s %(levelname)s %(asctime)s %(message)s" |
---|
14 | formatter = logging.Formatter( format ) |
---|
15 | handler.setFormatter( formatter ) |
---|
16 | log.addHandler( handler ) |
---|
17 | |
---|
18 | metadata = MetaData( migrate_engine ) |
---|
19 | db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) ) |
---|
20 | |
---|
21 | def 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 | |
---|
27 | HistoryDatasetAssociation_table = Table( "history_dataset_association", metadata, autoload=True ) |
---|
28 | |
---|
29 | def 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 | |
---|
57 | def downgrade(): |
---|
58 | pass |
---|