root/galaxy-central/lib/galaxy/model/migrate/versions/0008_galaxy_forms.py

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

import galaxy-central

行番号 
1"""
2This migration script adds the following new tables for supporting Galaxy forms:
31) form_definition_current
42) form_definition
53) form_values
64) request_type
75) request
86) sample
97) sample_state
108) sample_event
11"""
12from sqlalchemy import *
13from sqlalchemy.orm import *
14from sqlalchemy.exc import *
15from migrate import *
16from migrate.changeset import *
17
18import datetime
19now = datetime.datetime.utcnow
20
21import sys, logging
22log = logging.getLogger( __name__ )
23log.setLevel(logging.DEBUG)
24handler = logging.StreamHandler( sys.stdout )
25format = "%(name)s %(levelname)s %(asctime)s %(message)s"
26formatter = logging.Formatter( format )
27handler.setFormatter( formatter )
28log.addHandler( handler )
29
30# Need our custom types, but don't import anything else from model
31from galaxy.model.custom_types import *
32
33metadata = MetaData( migrate_engine )
34db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, autocommit=True ) )
35
36def display_migration_details():
37    print "========================================"
38    print "This migration script adds the following new tables for supporting Galaxy forms:"
39    print "1) form_definition_current"
40    print "2) form_definition"
41    print "3) form_values"
42    print "4) request_type"
43    print "5) request"
44    print "6) sample"
45    print "7) sample_state"
46    print "8) sample_event"
47    print "========================================"
48
49FormDefinitionCurrent_table = Table('form_definition_current', metadata,
50    Column( "id", Integer, primary_key=True),
51    Column( "create_time", DateTime, default=now ),
52    Column( "update_time", DateTime, default=now, onupdate=now ),
53    Column( "latest_form_id", Integer, index=True ),
54    Column( "deleted", Boolean, index=True, default=False ))
55
56FormDefinition_table = Table('form_definition', metadata,
57    Column( "id", Integer, primary_key=True),
58    Column( "create_time", DateTime, default=now ),
59    Column( "update_time", DateTime, default=now, onupdate=now ),
60    Column( "name", TrimmedString( 255 ), nullable=False ),
61    Column( "desc", TEXT ),
62    Column( "form_definition_current_id", Integer, ForeignKey( "form_definition_current.id" ), index=True, nullable=False ),
63    Column( "fields", JSONType()) )
64
65FormValues_table = Table('form_values', metadata,
66    Column( "id", Integer, primary_key=True),
67    Column( "create_time", DateTime, default=now ),
68    Column( "update_time", DateTime, default=now, onupdate=now ),
69    Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
70    Column( "content", JSONType()) )
71
72RequestType_table = Table('request_type', metadata,
73    Column( "id", Integer, primary_key=True),
74    Column( "create_time", DateTime, default=now ),
75    Column( "update_time", DateTime, default=now, onupdate=now ),
76    Column( "name", TrimmedString( 255 ), nullable=False ),
77    Column( "desc", TEXT ),
78    Column( "request_form_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
79    Column( "sample_form_id", Integer, ForeignKey( "form_definition.id" ), index=True ) )
80
81Request_table = Table('request', metadata,
82    Column( "id", Integer, primary_key=True),
83    Column( "create_time", DateTime, default=now ),
84    Column( "update_time", DateTime, default=now, onupdate=now ),
85    Column( "name", TrimmedString( 255 ), nullable=False ),
86    Column( "desc", TEXT ),
87    Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
88    Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), index=True ),
89    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
90    Column( "library_id", Integer, ForeignKey( "library.id" ), index=True ),
91    Column( "deleted", Boolean, index=True, default=False ) )
92
93Sample_table = Table('sample', metadata,
94    Column( "id", Integer, primary_key=True),
95    Column( "create_time", DateTime, default=now ),
96    Column( "update_time", DateTime, default=now, onupdate=now ),
97    Column( "name", TrimmedString( 255 ), nullable=False ),
98    Column( "desc", TEXT ),
99    Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
100    Column( "request_id", Integer, ForeignKey( "request.id" ), index=True ),
101    Column( "deleted", Boolean, index=True, default=False )  )
102
103SampleState_table = Table('sample_state', metadata,
104    Column( "id", Integer, primary_key=True),
105    Column( "create_time", DateTime, default=now ),
106    Column( "update_time", DateTime, default=now, onupdate=now ),
107    Column( "name", TrimmedString( 255 ), nullable=False ),
108    Column( "desc", TEXT ),
109    Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), index=True ) )
110
111SampleEvent_table = Table('sample_event', metadata,
112    Column( "id", Integer, primary_key=True),
113    Column( "create_time", DateTime, default=now ),
114    Column( "update_time", DateTime, default=now, onupdate=now ),
115    Column( "sample_id", Integer, ForeignKey( "sample.id" ), index=True ),
116    Column( "sample_state_id", Integer, ForeignKey( "sample_state.id" ), index=True ),
117    Column( "comment", TEXT ) )
118
119def upgrade():
120    display_migration_details()
121    # Load existing tables
122    metadata.reflect()
123    # Add all of the new tables above
124#    metadata.create_all()
125    try:
126        FormDefinitionCurrent_table.create()
127    except Exception, e:
128        log.debug( "Creating form_definition_current table failed: %s" % str( e ) )
129    try:
130        FormDefinition_table.create()
131    except Exception, e:
132        log.debug( "Creating form_definition table failed: %s" % str( e ) )
133    # Add 1 foreign key constraint to the form_definition_current table
134    if FormDefinitionCurrent_table and FormDefinition_table:
135        try:
136            cons = ForeignKeyConstraint( [FormDefinitionCurrent_table.c.latest_form_id],
137                                         [FormDefinition_table.c.id],
138                                         name='form_definition_current_latest_form_id_fk' )
139            # Create the constraint
140            cons.create()
141        except Exception, e:
142            log.debug( "Adding foreign key constraint 'form_definition_current_latest_form_id_fk' to table 'form_definition_current' failed: %s" % ( str( e ) ) )
143    try:
144        FormValues_table.create()
145    except Exception, e:
146        log.debug( "Creating form_values table failed: %s" % str( e ) ) 
147    try:
148        RequestType_table.create()
149    except Exception, e:
150        log.debug( "Creating request_type table failed: %s" % str( e ) ) 
151    try:
152        Request_table.create()
153    except Exception, e:
154        log.debug( "Creating request table failed: %s" % str( e ) ) 
155    try:
156        Sample_table.create()
157    except Exception, e:
158        log.debug( "Creating sample table failed: %s" % str( e ) ) 
159    try:
160        SampleState_table.create()
161    except Exception, e:
162        log.debug( "Creating sample_state table failed: %s" % str( e ) ) 
163    try:
164        SampleEvent_table.create()
165    except Exception, e:
166        log.debug( "Creating sample_event table failed: %s" % str( e ) ) 
167
168def downgrade():
169    # Load existing tables
170    metadata.reflect()
171    try:
172        FormDefinition_table.drop()
173    except Exception, e:
174        log.debug( "Dropping form_definition table failed: %s" % str( e ) ) 
175    try:
176        FormDefinitionCurrent_table.drop()
177    except Exception, e:
178        log.debug( "Dropping form_definition_current table failed: %s" % str( e ) ) 
179    try:
180        FormValues_table.drop()
181    except Exception, e:
182        log.debug( "Dropping form_values table failed: %s" % str( e ) ) 
183    try:
184        Request_table.drop()
185    except Exception, e:
186        log.debug( "Dropping request table failed: %s" % str( e ) ) 
187    try:
188        RequestType_table.drop()
189    except Exception, e:
190        log.debug( "Dropping request_type table failed: %s" % str( e ) ) 
191    try:
192        Sample_table.drop()
193    except Exception, e:
194        log.debug( "Dropping sample table failed: %s" % str( e ) ) 
195    try:
196        SampleState_table.drop()
197    except Exception, e:
198        log.debug( "Dropping sample_state table failed: %s" % str( e ) ) 
199    try:
200        SampleEvent_table.drop()
201    except Exception, e:
202        log.debug( "Dropping sample_event table failed: %s" % str( e ) )     
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。