root/galaxy-central/lib/galaxy/model/migrate/versions/0038_add_inheritable_column_to_library_template_assoc_tables.py @ 2

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

import galaxy-central

行番号 
1"""
2Migration script to add an inheritable column to the following tables:
3library_info_association, library_folder_info_association.
4Also, in case of sqlite check if the previous migration script deleted the
5request table and if so, restore the table.
6"""
7
8from sqlalchemy import *
9from migrate import *
10from migrate.changeset import *
11from galaxy.model.custom_types import *
12import datetime
13now = datetime.datetime.utcnow
14import logging
15log = logging.getLogger( __name__ )
16
17metadata = MetaData( migrate_engine )
18
19def upgrade():
20    print __doc__
21   
22    #
23    # In case of sqlite, check if the previous migration script deleted the
24    # request table and if so, restore the table.
25    #
26    if migrate_engine.name == 'sqlite':
27        if not migrate_engine.has_table('request'):
28            # load the tables referenced in foreign keys
29            metadata.reflect(only=['form_values', 'request_type', 'galaxy_user'])
30            # create a temporary table
31            Request_table = Table( 'request', metadata,
32                                    Column( "id", Integer, primary_key=True),
33                                    Column( "create_time", DateTime, default=now ),
34                                    Column( "update_time", DateTime, default=now, onupdate=now ),
35                                    Column( "name", TrimmedString( 255 ), nullable=False ),
36                                    Column( "desc", TEXT ),
37                                    Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
38                                    Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), index=True ),
39                                    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
40                                    Column( "deleted", Boolean, index=True, default=False ) )
41            try:
42                Request_table.create()
43            except Exception, e:
44                log.debug( "Creating request table failed: %s" % str( e ) ) 
45
46    metadata.reflect()
47   
48    LibraryInfoAssociation_table = Table( "library_info_association", metadata, autoload=True )
49    c = Column( "inheritable", Boolean, index=True, default=False )
50    c.create( LibraryInfoAssociation_table )
51    assert c is LibraryInfoAssociation_table.c.inheritable
52    cmd = "UPDATE library_info_association SET inheritable = false"
53    try:
54        db_session.execute( cmd )
55    except Exception, e:
56        log.debug( "Setting value of column inheritable to false in library_info_association failed: %s" % ( str( e ) ) )
57   
58    LibraryFolderInfoAssociation_table = Table( "library_folder_info_association", metadata, autoload=True )
59    c = Column( "inheritable", Boolean, index=True, default=False )
60    c.create( LibraryFolderInfoAssociation_table )
61    assert c is LibraryFolderInfoAssociation_table.c.inheritable
62    cmd = "UPDATE library_folder_info_association SET inheritable = false"
63    try:
64        db_session.execute( cmd )
65    except Exception, e:
66        log.debug( "Setting value of column inheritable to false in library_folder_info_association failed: %s" % ( str( e ) ) )
67
68def downgrade():
69    pass
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。