| 1 | """ |
|---|
| 2 | This script adds 3 indexes to table columns: library_folder.name, |
|---|
| 3 | library_dataset.name, library_dataset_dataset_association.name. |
|---|
| 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 | LibraryFolder_table = Table( "library_folder", metadata, autoload=True ) |
|---|
| 21 | LibraryDatasetDatasetAssociation_table = Table( "library_dataset_dataset_association", metadata, autoload=True ) |
|---|
| 22 | LibraryDataset_table = Table( "library_dataset", metadata, autoload=True ) |
|---|
| 23 | |
|---|
| 24 | def 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 | |
|---|
| 30 | def 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 ) ) ) |
|---|
| 52 | def downgrade(): |
|---|
| 53 | log.debug( "Downgrade is not possible." ) |
|---|