root/galaxy-central/lib/galaxy/model/migrate/versions/0019_request_library_folder.py

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

import galaxy-central

行番号 
1from sqlalchemy import *
2from sqlalchemy.orm import *
3from sqlalchemy.exc import *
4from migrate import *
5from migrate.changeset import *
6import datetime
7now = datetime.datetime.utcnow
8import sys, logging
9# Need our custom types, but don't import anything else from model
10from galaxy.model.custom_types import *
11
12log = logging.getLogger( __name__ )
13log.setLevel(logging.DEBUG)
14handler = logging.StreamHandler( sys.stdout )
15format = "%(name)s %(levelname)s %(asctime)s %(message)s"
16formatter = logging.Formatter( format )
17handler.setFormatter( formatter )
18log.addHandler( handler )
19
20metadata = MetaData( migrate_engine )
21db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )
22
23def display_migration_details():
24    print "========================================"
25    print """This script creates a request.folder_id column which is a foreign
26key to the library_folder table. This also adds a 'type' and 'layout' column
27to the form_definition table."""
28    print "========================================"
29
30def upgrade():
31    display_migration_details()
32    # Load existing tables
33    metadata.reflect()
34    # Create the folder_id column
35    try:
36        Request_table = Table( "request", metadata, autoload=True )
37    except NoSuchTableError:
38        Request_table = None
39        log.debug( "Failed loading table request" )
40    if Request_table:
41        try:
42            col = Column( "folder_id", Integer, index=True )
43            col.create( Request_table )
44            assert col is Request_table.c.folder_id
45        except Exception, e:
46            log.debug( "Adding column 'folder_id' to request table failed: %s" % ( str( e ) ) )
47        try:
48            LibraryFolder_table = Table( "library_folder", metadata, autoload=True )
49        except NoSuchTableError:
50            LibraryFolder_table = None
51            log.debug( "Failed loading table library_folder" )
52        # Add 1 foreign key constraint to the library_folder table
53        if Request_table and LibraryFolder_table:
54            try:
55                cons = ForeignKeyConstraint( [Request_table.c.folder_id],
56                                             [LibraryFolder_table.c.id],
57                                             name='request_folder_id_fk' )
58                # Create the constraint
59                cons.create()
60            except Exception, e:
61                log.debug( "Adding foreign key constraint 'request_folder_id_fk' to table 'library_folder' failed: %s" % ( str( e ) ) )
62    # Create the type column in form_definition
63    try:
64        FormDefinition_table = Table( "form_definition", metadata, autoload=True )
65    except NoSuchTableError:
66        FormDefinition_table = None
67        log.debug( "Failed loading table form_definition" )
68    if FormDefinition_table:
69        try:
70            col = Column( "type", TrimmedString( 255 ), index=True )
71            col.create( FormDefinition_table )
72            assert col is FormDefinition_table.c.type
73        except Exception, e:
74            log.debug( "Adding column 'type' to form_definition table failed: %s" % ( str( e ) ) )
75        try:
76            col = Column( "layout", JSONType())
77            col.create( FormDefinition_table )
78            assert col is FormDefinition_table.c.layout
79        except Exception, e:
80            log.debug( "Adding column 'layout' to form_definition table failed: %s" % ( str( e ) ) )
81
82
83def downgrade():
84    pass
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。