1 | """ |
---|
2 | Migration script to add an inheritable column to the following tables: |
---|
3 | library_info_association, library_folder_info_association. |
---|
4 | Also, in case of sqlite check if the previous migration script deleted the |
---|
5 | request table and if so, restore the table. |
---|
6 | """ |
---|
7 | |
---|
8 | from sqlalchemy import * |
---|
9 | from migrate import * |
---|
10 | from migrate.changeset import * |
---|
11 | from galaxy.model.custom_types import * |
---|
12 | import datetime |
---|
13 | now = datetime.datetime.utcnow |
---|
14 | import logging |
---|
15 | log = logging.getLogger( __name__ ) |
---|
16 | |
---|
17 | metadata = MetaData( migrate_engine ) |
---|
18 | |
---|
19 | def 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 | |
---|
68 | def downgrade(): |
---|
69 | pass |
---|