root/galaxy-central/lib/galaxy/model/migrate/versions/0009_request_table.py

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

import galaxy-central

行番号 
1"""
2This migration script adds a new column to 2 tables:
31) a new boolean type column named 'submitted' to the 'request' table
42) a new string type column named 'bar_code' to the 'sample' table
5"""
6from sqlalchemy import *
7from sqlalchemy.orm import *
8from migrate import *
9from migrate.changeset import *
10import sys, logging
11from galaxy.model.custom_types import *
12from sqlalchemy.exc import *
13
14log = logging.getLogger( __name__ )
15log.setLevel(logging.DEBUG)
16handler = logging.StreamHandler( sys.stdout )
17format = "%(name)s %(levelname)s %(asctime)s %(message)s"
18formatter = logging.Formatter( format )
19handler.setFormatter( formatter )
20log.addHandler( handler )
21
22metadata = MetaData( migrate_engine )
23
24def display_migration_details():
25    print "========================================"
26    print "This migration script adds a new column to 2 tables:"
27    print "1) a new boolean type column named 'submitted' to the 'request' table"
28    print "2) a new string type column named 'bar_code' to the 'sample' table"
29    print "========================================"
30
31def upgrade():
32    display_migration_details()
33    # Load existing tables
34    metadata.reflect()
35    # Add 1 column to the request table
36    try:
37        Request_table = Table( "request", metadata, autoload=True )
38    except NoSuchTableError:
39        Request_table = None
40        log.debug( "Failed loading table request" )
41    if Request_table:
42        try:
43            col = Column( "submitted", Boolean, index=True, default=False )
44            col.create( Request_table )
45            assert col is Request_table.c.submitted
46        except Exception, e:
47            log.debug( "Adding column 'submitted' to request table failed: %s" % ( str( e ) ) )
48    # Add 1 column to the sample table
49    try:
50        Sample_table = Table( "sample", metadata, autoload=True )
51    except NoSuchTableError:
52        Sample_table = None
53        log.debug( "Failed loading table sample" )
54    if Sample_table:
55        try:
56            col = Column( "bar_code", TrimmedString( 255 ), index=True )
57            col.create( Sample_table )
58            assert col is Sample_table.c.bar_code
59        except Exception, e:
60            log.debug( "Adding column 'bar_code' to sample table failed: %s" % ( str( e ) ) )
61
62def downgrade():
63    pass
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。