root/galaxy-central/lib/galaxy/model/migrate/versions/0017_library_item_indexes.py

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

import galaxy-central

行番号 
1"""
2This script adds 3 indexes to table columns: library_folder.name,
3library_dataset.name, library_dataset_dataset_association.name.
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 ) )
20LibraryFolder_table = Table( "library_folder", metadata, autoload=True )
21LibraryDatasetDatasetAssociation_table = Table( "library_dataset_dataset_association", metadata, autoload=True )
22LibraryDataset_table = Table( "library_dataset", metadata, autoload=True )
23         
24def display_migration_details():
25    print "========================================"
26    print "This script adds 3 indexes to table columns: library_folder.name,"
27    print "library_dataset.name, library_dataset_dataset_association.name."
28    print "========================================"
29       
30def upgrade():
31    display_migration_details()
32    # Load existing tables
33    metadata.reflect()
34    # Add 1 index to the library_folder table
35    i = Index( 'ix_library_folder_name', LibraryFolder_table.c.name )
36    try:
37        i.create()
38    except Exception, e:
39        log.debug( "Adding index 'ix_library_folder_name' to library_folder table failed: %s" % ( str( e ) ) )
40    # Add 1 index to the library_dataset_dataset_association table
41    i = Index( 'ix_library_dataset_dataset_association_name', LibraryDatasetDatasetAssociation_table.c.name )
42    try:
43        i.create()
44    except Exception, e:
45        log.debug( "Adding index 'ix_library_dataset_dataset_association_name' to library_dataset_dataset_association table failed: %s" % ( str( e ) ) )
46    # Add 1 index to the library_dataset table
47    i = Index( 'ix_library_dataset_name', LibraryDataset_table.c.name )
48    try:
49        i.create()
50    except Exception, e:
51        log.debug( "Adding index 'ix_library_dataset_name' to library_dataset table failed: %s" % ( str( e ) ) )
52def downgrade():
53    log.debug( "Downgrade is not possible." )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。