root/galaxy-central/lib/galaxy/model/migrate/versions/0033_published_cols_for_histories_and_workflows.py @ 2

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

import galaxy-central

行番号 
1"""
2Migration script to add necessary columns for distinguishing between viewing/importing and publishing histories, \
3workflows, and pages. Script adds published column to histories and workflows and importable column to pages.
4"""
5
6from sqlalchemy import *
7from sqlalchemy.orm import *
8from migrate import *
9from migrate.changeset import *
10
11import logging
12log = logging.getLogger( __name__ )
13
14metadata = MetaData( migrate_engine )
15db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )
16
17def upgrade():
18        print __doc__
19        metadata.reflect()
20
21        # Create published column in history table.
22        History_table = Table( "history", metadata, autoload=True )
23        c = Column( "published", Boolean, index=True )
24        try:
25            c.create( History_table )
26            assert c is History_table.c.published
27        except Exception, e:
28            print "Adding published column to history table failed: %s" % str( e )
29            log.debug( "Adding published column to history table failed: %s" % str( e ) )
30   
31   
32        # Create index for published column in history table.
33        try:
34            i = Index( "ix_history_published", History_table.c.published )
35            i.create()
36        except:
37            # Mysql doesn't have a named index, but alter should work
38            History_table.c.published.alter( unique=False )
39   
40        # Create published column in stored workflows table.
41        StoredWorkflow_table = Table( "stored_workflow", metadata, autoload=True )
42        c = Column( "published", Boolean, index=True )
43        try:
44            c.create( StoredWorkflow_table )
45            assert c is StoredWorkflow_table.c.published
46        except Exception, e:
47            print "Adding published column to stored_workflow table failed: %s" % str( e )
48            log.debug( "Adding published column to stored_workflow table failed: %s" % str( e ) )
49
50        # Create index for published column in stored workflows table.
51        try:
52            i = Index( "ix_stored_workflow_published", StoredWorkflow_table.c.published )
53            i.create()
54        except:
55            # Mysql doesn't have a named index, but alter should work
56            StoredWorkflow_table.c.published.alter( unique=False )
57
58        # Create importable column in page table.
59        Page_table = Table( "page", metadata, autoload=True )
60        c = Column( "importable", Boolean, index=True )
61        try:
62                c.create( Page_table )
63                assert c is Page_table.c.importable
64        except Exception, e:
65                print "Adding importable column to page table failed: %s" % str( e )
66                log.debug( "Adding importable column to page table failed: %s" % str( e ) )
67               
68        # Create index for importable column in page table.
69        try:
70            i = Index( "ix_page_importable", Page_table.c.importable )
71            i.create()
72        except:
73            # Mysql doesn't have a named index, but alter should work
74                Page_table.c.importable.alter( unique=False )
75
76def downgrade():
77        metadata.reflect()
78
79        # Drop published column from history table.
80        History_table = Table( "history", metadata, autoload=True )
81        try:
82            History_table.c.published.drop()
83        except Exception, e:
84            print "Dropping column published from history table failed: %s" % str( e )
85            log.debug( "Dropping column published from history table failed: %s" % str( e ) )
86   
87        # Drop published column from stored_workflow table.
88        StoredWorkflow_table = Table( "stored_workflow", metadata, autoload=True )
89        try:
90            StoredWorkflow_table.c.published.drop()
91        except Exception, e:
92            print "Dropping column published from stored_workflow table failed: %s" % str( e )
93            log.debug( "Dropping column published from stored_workflow table failed: %s" % str( e ) )
94       
95    # Drop importable column from page table.
96        Page_table = Table( "page", metadata, autoload=True )
97        try:
98                Page_table.c.importable.drop()
99        except Exception, e:
100                print "Dropping column importable from page table failed: %s" % str( e )
101                log.debug( "Dropping column importable from page table failed: %s" % str( e ) )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。