root/galaxy-central/lib/galaxy/model/migrate/versions/0007_sharing_histories.py

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

import galaxy-central

行番号 
1"""
2This migration script creates the new history_user_share_association table, and adds
3a new boolean type column to the history table.  This provides support for sharing
4histories in the same way that workflows are shared.
5"""
6from sqlalchemy import *
7from sqlalchemy.orm import *
8from migrate import *
9from migrate.changeset import *
10import sys, logging
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 )
21
22def display_migration_details():
23    print "========================================"
24    print "This migration script creates the new history_user_share_association table, and adds"
25    print "a new boolean type column to the history table.  This provides support for sharing"
26    print "histories in the same way that workflows are shared."
27    print "========================================"
28
29HistoryUserShareAssociation_table = Table( "history_user_share_association", metadata,
30    Column( "id", Integer, primary_key=True ),
31    Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
32    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True )
33    )
34
35def upgrade():
36    display_migration_details()
37    # Load existing tables
38    metadata.reflect()
39    # Create the history_user_share_association table
40    try:
41        HistoryUserShareAssociation_table.create()
42    except Exception, e:
43        log.debug( "Creating history_user_share_association table failed: %s" % str( e ) )
44    # Add 1 column to the history table
45    try:
46        History_table = Table( "history", metadata, autoload=True )
47    except NoSuchTableError:
48        History_table = None
49        log.debug( "Failed loading table history" )
50    if History_table:
51        try:
52            col = Column( 'importable', Boolean, index=True, default=False )
53            col.create( History_table )
54            assert col is History_table.c.importable
55        except Exception, e:
56            log.debug( "Adding column 'importable' to history table failed: %s" % ( str( e ) ) )
57
58def downgrade():
59    # Load existing tables
60    metadata.reflect()
61    # Drop 1 column from the history table
62    try:
63        History_table = Table( "history", metadata, autoload=True )
64    except NoSuchTableError:
65        History_table = None
66        log.debug( "Failed loading table history" )
67    if History_table:
68        try:
69            col = History_table.c.importable
70            col.drop()
71        except Exception, e:
72            log.debug( "Dropping column 'importable' from history table failed: %s" % ( str( e ) ) )
73    # Drop the history_user_share_association table
74    try:
75        HistoryUserShareAssociation_table.drop()
76    except Exception, e:
77        log.debug( "Dropping history_user_share_association table failed: %s" % str( e ) )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。