PageRenderTime 96ms CodeModel.GetById 23ms app.highlight 67ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/galaxy/model/mapping.py

https://bitbucket.org/h_morita_dbcls/galaxy-central
Python | 1515 lines | 1248 code | 206 blank | 61 comment | 1 complexity | 54ee52f8bc7d0b011a8a09f1ad39b4f0 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1"""
  2Details of how the data model objects are mapped onto the relational database
  3are encapsulated here. 
  4"""
  5import logging
  6log = logging.getLogger( __name__ )
  7
  8import sys
  9import datetime
 10
 11from galaxy.model import *
 12from galaxy.model.orm import *
 13from galaxy.model.orm.ext.assignmapper import *
 14from galaxy.model.custom_types import *
 15from galaxy.util.bunch import Bunch
 16from galaxy.security import GalaxyRBACAgent
 17from sqlalchemy.orm.collections import attribute_mapped_collection
 18from sqlalchemy.ext.associationproxy import association_proxy
 19
 20metadata = MetaData()
 21context = Session = scoped_session( sessionmaker( autoflush=False, autocommit=True ) )
 22
 23# For backward compatibility with "context.current"
 24context.current = Session
 25
 26dialect_to_egg = { 
 27    "sqlite"   : "pysqlite>=2",
 28    "postgres" : "psycopg2",
 29    "mysql"    : "MySQL_python"
 30}
 31
 32# NOTE REGARDING TIMESTAMPS:
 33#   It is currently difficult to have the timestamps calculated by the 
 34#   database in a portable way, so we're doing it in the client. This
 35#   also saves us from needing to postfetch on postgres. HOWEVER: it
 36#   relies on the client's clock being set correctly, so if clustering
 37#   web servers, use a time server to ensure synchronization
 38
 39# Return the current time in UTC without any timezone information
 40now = datetime.datetime.utcnow
 41
 42User.table = Table( "galaxy_user", metadata,
 43    Column( "id", Integer, primary_key=True),
 44    Column( "create_time", DateTime, default=now ),
 45    Column( "update_time", DateTime, default=now, onupdate=now ),
 46    Column( "email", TrimmedString( 255 ), nullable=False ),
 47    Column( "username", TrimmedString( 255 ), index=True, unique=True ),
 48    Column( "password", TrimmedString( 40 ), nullable=False ),
 49    Column( "external", Boolean, default=False ),
 50    Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
 51    Column( "deleted", Boolean, index=True, default=False ),
 52    Column( "purged", Boolean, index=True, default=False ) )
 53
 54UserAddress.table = Table( "user_address", metadata,
 55    Column( "id", Integer, primary_key=True),
 56    Column( "create_time", DateTime, default=now ),
 57    Column( "update_time", DateTime, default=now, onupdate=now ),
 58    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
 59    Column( "desc", TrimmedString( 255 )),    
 60    Column( "name", TrimmedString( 255 ), nullable=False),
 61    Column( "institution", TrimmedString( 255 )),
 62    Column( "address", TrimmedString( 255 ), nullable=False),
 63    Column( "city", TrimmedString( 255 ), nullable=False),
 64    Column( "state", TrimmedString( 255 ), nullable=False),
 65    Column( "postal_code", TrimmedString( 255 ), nullable=False),
 66    Column( "country", TrimmedString( 255 ), nullable=False),
 67    Column( "phone", TrimmedString( 255 )),
 68    Column( "deleted", Boolean, index=True, default=False ),
 69    Column( "purged", Boolean, index=True, default=False ) )
 70
 71History.table = Table( "history", metadata,
 72    Column( "id", Integer, primary_key=True),
 73    Column( "create_time", DateTime, default=now ),
 74    Column( "update_time", DateTime, index=True, default=now, onupdate=now ),
 75    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
 76    Column( "name", TrimmedString( 255 ) ),
 77    Column( "hid_counter", Integer, default=1 ),
 78    Column( "deleted", Boolean, index=True, default=False ),
 79    Column( "purged", Boolean, index=True, default=False ),
 80    Column( "genome_build", TrimmedString( 40 ) ),
 81    Column( "importable", Boolean, default=False ),
 82    Column( "slug", TEXT, index=True ),
 83    Column( "published", Boolean, index=True, default=False ) )
 84
 85HistoryUserShareAssociation.table = Table( "history_user_share_association", metadata,
 86    Column( "id", Integer, primary_key=True ),
 87    Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
 88    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True )
 89    )
 90
 91HistoryDatasetAssociation.table = Table( "history_dataset_association", metadata, 
 92    Column( "id", Integer, primary_key=True ),
 93    Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
 94    Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ),
 95    Column( "create_time", DateTime, default=now ),
 96    Column( "update_time", DateTime, default=now, onupdate=now ),
 97    Column( "state", TrimmedString( 64 ), index=True, key="_state" ),
 98    Column( "copied_from_history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), nullable=True ),
 99    Column( "copied_from_library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True ),
100    Column( "hid", Integer ),
101    Column( "name", TrimmedString( 255 ) ),
102    Column( "info", TrimmedString( 255 ) ),
103    Column( "blurb", TrimmedString( 255 ) ),
104    Column( "peek" , TEXT ),
105    Column( "extension", TrimmedString( 64 ) ),
106    Column( "metadata", MetadataType(), key="_metadata" ),
107    Column( "parent_id", Integer, ForeignKey( "history_dataset_association.id" ), nullable=True ),
108    Column( "designation", TrimmedString( 255 ) ),
109    Column( "deleted", Boolean, index=True, default=False ),
110    Column( "visible", Boolean ) )
111
112Dataset.table = Table( "dataset", metadata, 
113    Column( "id", Integer, primary_key=True ),
114    Column( "create_time", DateTime, default=now ),
115    Column( "update_time", DateTime, index=True, default=now, onupdate=now ),
116    Column( "state", TrimmedString( 64 ), index=True ),
117    Column( "deleted", Boolean, index=True, default=False ),
118    Column( "purged", Boolean, index=True, default=False ),
119    Column( "purgable", Boolean, default=True ),
120    Column( "external_filename" , TEXT ),
121    Column( "_extra_files_path", TEXT ),
122    Column( 'file_size', Numeric( 15, 0 ) ) )
123
124HistoryDatasetAssociationDisplayAtAuthorization.table = Table( "history_dataset_association_display_at_authorization", metadata,
125    Column( "id", Integer, primary_key=True ),
126    Column( "create_time", DateTime, default=now ),
127    Column( "update_time", DateTime, index=True, default=now, onupdate=now ),
128    Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
129    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
130    Column( "site", TrimmedString( 255 ) ) )
131
132ImplicitlyConvertedDatasetAssociation.table = Table( "implicitly_converted_dataset_association", metadata,
133    Column( "id", Integer, primary_key=True ),
134    Column( "create_time", DateTime, default=now ),
135    Column( "update_time", DateTime, default=now, onupdate=now ),
136    Column( "hda_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True, nullable=True ),
137    Column( "hda_parent_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
138    Column( "deleted", Boolean, index=True, default=False ),
139    Column( "metadata_safe", Boolean, index=True, default=True ),
140    Column( "type", TrimmedString( 255 ) ) )
141
142ValidationError.table = Table( "validation_error", metadata,
143    Column( "id", Integer, primary_key=True ),
144    Column( "dataset_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
145    Column( "message", TrimmedString( 255 ) ),
146    Column( "err_type", TrimmedString( 64 ) ),
147    Column( "attributes", TEXT ) )
148
149Group.table = Table( "galaxy_group", metadata,
150    Column( "id", Integer, primary_key=True ),
151    Column( "create_time", DateTime, default=now ),
152    Column( "update_time", DateTime, default=now, onupdate=now ),
153    Column( "name", String( 255 ), index=True, unique=True ),
154    Column( "deleted", Boolean, index=True, default=False ) )
155
156UserGroupAssociation.table = Table( "user_group_association", metadata, 
157    Column( "id", Integer, primary_key=True ),
158    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
159    Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),
160    Column( "create_time", DateTime, default=now ),
161    Column( "update_time", DateTime, default=now, onupdate=now ) )
162
163UserRoleAssociation.table = Table( "user_role_association", metadata,
164    Column( "id", Integer, primary_key=True ),
165    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
166    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ),
167    Column( "create_time", DateTime, default=now ),
168    Column( "update_time", DateTime, default=now, onupdate=now ) )
169
170GroupRoleAssociation.table = Table( "group_role_association", metadata,
171    Column( "id", Integer, primary_key=True ),
172    Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),
173    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ),
174    Column( "create_time", DateTime, default=now ),
175    Column( "update_time", DateTime, default=now, onupdate=now ) )
176
177Role.table = Table( "role", metadata,
178    Column( "id", Integer, primary_key=True ),
179    Column( "create_time", DateTime, default=now ),
180    Column( "update_time", DateTime, default=now, onupdate=now ),
181    Column( "name", String( 255 ), index=True, unique=True ),
182    Column( "description", TEXT ),
183    Column( "type", String( 40 ), index=True ),
184    Column( "deleted", Boolean, index=True, default=False ) )
185
186DatasetPermissions.table = Table( "dataset_permissions", metadata,
187    Column( "id", Integer, primary_key=True ),
188    Column( "create_time", DateTime, default=now ),
189    Column( "update_time", DateTime, default=now, onupdate=now ),
190    Column( "action", TEXT ),
191    Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ),
192    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
193
194LibraryPermissions.table = Table( "library_permissions", metadata,
195    Column( "id", Integer, primary_key=True ),
196    Column( "create_time", DateTime, default=now ),
197    Column( "update_time", DateTime, default=now, onupdate=now ),
198    Column( "action", TEXT ),
199    Column( "library_id", Integer, ForeignKey( "library.id" ), nullable=True, index=True ),
200    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
201
202LibraryFolderPermissions.table = Table( "library_folder_permissions", metadata,
203    Column( "id", Integer, primary_key=True ),
204    Column( "create_time", DateTime, default=now ),
205    Column( "update_time", DateTime, default=now, onupdate=now ),
206    Column( "action", TEXT ),
207    Column( "library_folder_id", Integer, ForeignKey( "library_folder.id" ), nullable=True, index=True ),
208    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
209
210LibraryDatasetPermissions.table = Table( "library_dataset_permissions", metadata,
211    Column( "id", Integer, primary_key=True ),
212    Column( "create_time", DateTime, default=now ),
213    Column( "update_time", DateTime, default=now, onupdate=now ),
214    Column( "action", TEXT ),
215    Column( "library_dataset_id", Integer, ForeignKey( "library_dataset.id" ), nullable=True, index=True ),
216    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
217
218LibraryDatasetDatasetAssociationPermissions.table = Table( "library_dataset_dataset_association_permissions", metadata,
219    Column( "id", Integer, primary_key=True ),
220    Column( "create_time", DateTime, default=now ),
221    Column( "update_time", DateTime, default=now, onupdate=now ),
222    Column( "action", TEXT ),
223    Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True, index=True ),
224    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
225
226DefaultUserPermissions.table = Table( "default_user_permissions", metadata,
227    Column( "id", Integer, primary_key=True ),
228    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
229    Column( "action", TEXT ),
230    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
231
232DefaultHistoryPermissions.table = Table( "default_history_permissions", metadata,
233    Column( "id", Integer, primary_key=True ),
234    Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
235    Column( "action", TEXT ),
236    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
237
238LibraryDataset.table = Table( "library_dataset", metadata, 
239    Column( "id", Integer, primary_key=True ),
240    Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id", use_alter=True, name="library_dataset_dataset_association_id_fk" ), nullable=True, index=True ),#current version of dataset, if null, there is not a current version selected
241    Column( "folder_id", Integer, ForeignKey( "library_folder.id" ), index=True ),
242    Column( "order_id", Integer ), #not currently being used, but for possible future use
243    Column( "create_time", DateTime, default=now ),
244    Column( "update_time", DateTime, default=now, onupdate=now ),
245    Column( "name", TrimmedString( 255 ), key="_name", index=True ), #when not None/null this will supercede display in library (but not when imported into user's history?)
246    Column( "info", TrimmedString( 255 ),  key="_info" ), #when not None/null this will supercede display in library (but not when imported into user's history?)
247    Column( "deleted", Boolean, index=True, default=False ) )
248
249LibraryDatasetDatasetAssociation.table = Table( "library_dataset_dataset_association", metadata, 
250    Column( "id", Integer, primary_key=True ),
251    Column( "library_dataset_id", Integer, ForeignKey( "library_dataset.id" ), index=True ),
252    Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ),
253    Column( "create_time", DateTime, default=now ),
254    Column( "update_time", DateTime, default=now, onupdate=now ),
255    Column( "state", TrimmedString( 64 ), index=True, key="_state" ),
256    Column( "copied_from_history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id", use_alter=True, name='history_dataset_association_dataset_id_fkey' ), nullable=True ),
257    Column( "copied_from_library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id", use_alter=True, name='library_dataset_dataset_association_id_fkey' ), nullable=True ),
258    Column( "name", TrimmedString( 255 ), index=True ),
259    Column( "info", TrimmedString( 255 ) ),
260    Column( "blurb", TrimmedString( 255 ) ),
261    Column( "peek" , TEXT ),
262    Column( "extension", TrimmedString( 64 ) ),
263    Column( "metadata", MetadataType(), key="_metadata" ),
264    Column( "parent_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True ),
265    Column( "designation", TrimmedString( 255 ) ),
266    Column( "deleted", Boolean, index=True, default=False ),
267    Column( "visible", Boolean ),
268    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
269    Column( "message", TrimmedString( 255 ) ) )
270
271Library.table = Table( "library", metadata,
272    Column( "id", Integer, primary_key=True ),
273    Column( "root_folder_id", Integer, ForeignKey( "library_folder.id" ), index=True ),
274    Column( "create_time", DateTime, default=now ),
275    Column( "update_time", DateTime, default=now, onupdate=now ),
276    Column( "name", String( 255 ), index=True ),
277    Column( "deleted", Boolean, index=True, default=False ),
278    Column( "purged", Boolean, index=True, default=False ),
279    Column( "description", TEXT ),
280    Column( "synopsis", TEXT ) )
281
282LibraryFolder.table = Table( "library_folder", metadata,
283    Column( "id", Integer, primary_key=True ),
284    Column( "parent_id", Integer, ForeignKey( "library_folder.id" ), nullable = True, index=True ),
285    Column( "create_time", DateTime, default=now ),
286    Column( "update_time", DateTime, default=now, onupdate=now ),
287    Column( "name", TEXT, index=True ),
288    Column( "description", TEXT ),
289    Column( "order_id", Integer ), #not currently being used, but for possible future use
290    Column( "item_count", Integer ),
291    Column( "deleted", Boolean, index=True, default=False ),
292    Column( "purged", Boolean, index=True, default=False ),
293    Column( "genome_build", TrimmedString( 40 ) ) )
294
295LibraryInfoAssociation.table = Table( 'library_info_association', metadata,
296    Column( "id", Integer, primary_key=True ),
297    Column( "library_id", Integer, ForeignKey( "library.id" ), index=True ),
298    Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
299    Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
300    Column( "inheritable", Boolean, index=True, default=False ),
301    Column( "deleted", Boolean, index=True, default=False ) )
302
303LibraryFolderInfoAssociation.table = Table( 'library_folder_info_association', metadata,
304    Column( "id", Integer, primary_key=True ),
305    Column( "library_folder_id", Integer, ForeignKey( "library_folder.id" ), nullable=True, index=True ),
306    Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
307    Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
308    Column( "inheritable", Boolean, index=True, default=False ),
309    Column( "deleted", Boolean, index=True, default=False ) )
310
311LibraryDatasetDatasetInfoAssociation.table = Table( 'library_dataset_dataset_info_association', metadata,
312    Column( "id", Integer, primary_key=True ),
313    Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True, index=True ),
314    Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
315    Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
316    Column( "deleted", Boolean, index=True, default=False ) )
317
318Job.table = Table( "job", metadata,
319    Column( "id", Integer, primary_key=True ),
320    Column( "create_time", DateTime, default=now ),
321    Column( "update_time", DateTime, default=now, onupdate=now ),
322    Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
323    Column( "library_folder_id", Integer, ForeignKey( "library_folder.id" ), index=True ),
324    Column( "tool_id", String( 255 ) ),
325    Column( "tool_version", TEXT, default="1.0.0" ),
326    Column( "state", String( 64 ), index=True ),
327    Column( "info", TrimmedString( 255 ) ),
328    Column( "command_line", TEXT ), 
329    Column( "param_filename", String( 1024 ) ),
330    Column( "runner_name", String( 255 ) ),
331    Column( "stdout", TEXT ),
332    Column( "stderr", TEXT ),
333    Column( "traceback", TEXT ),
334    Column( "session_id", Integer, ForeignKey( "galaxy_session.id" ), index=True, nullable=True ),
335    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=True ),
336    Column( "job_runner_name", String( 255 ) ),
337    Column( "job_runner_external_id", String( 255 ) ), 
338    Column( "imported", Boolean, default=False, index=True ) )
339    
340JobParameter.table = Table( "job_parameter", metadata,
341    Column( "id", Integer, primary_key=True ),
342    Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
343    Column( "name", String(255) ),
344    Column( "value", TEXT ) )
345    
346JobToInputDatasetAssociation.table = Table( "job_to_input_dataset", metadata,
347    Column( "id", Integer, primary_key=True ),
348    Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
349    Column( "dataset_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
350    Column( "name", String(255) ) )
351    
352JobToOutputDatasetAssociation.table = Table( "job_to_output_dataset", metadata,
353    Column( "id", Integer, primary_key=True ),
354    Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
355    Column( "dataset_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
356    Column( "name", String(255) ) )
357    
358JobToOutputLibraryDatasetAssociation.table = Table( "job_to_output_library_dataset", metadata,
359    Column( "id", Integer, primary_key=True ),
360    Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
361    Column( "ldda_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), index=True ),
362    Column( "name", String(255) ) )
363    
364JobExternalOutputMetadata.table = Table( "job_external_output_metadata", metadata,
365    Column( "id", Integer, primary_key=True ),
366    Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
367    Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True, nullable=True ),
368    Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), index=True, nullable=True ),
369    Column( "filename_in", String( 255 ) ),
370    Column( "filename_out", String( 255 ) ),
371    Column( "filename_results_code", String( 255 ) ),
372    Column( "filename_kwds", String( 255 ) ),
373    Column( "filename_override_metadata", String( 255 ) ),
374    Column( "job_runner_external_pid", String( 255 ) ) )
375    
376PostJobAction.table = Table("post_job_action", metadata,
377    Column("id", Integer, primary_key=True),
378    Column("workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True, nullable=False),
379    Column("action_type", String(255), nullable=False),
380    Column("output_name", String(255), nullable=True),
381    Column("action_arguments", JSONType, nullable=True))
382
383PostJobActionAssociation.table = Table("post_job_action_association", metadata,
384    Column("id", Integer, primary_key=True),
385    Column("job_id", Integer, ForeignKey( "job.id" ), index=True, nullable=False),
386    Column("post_job_action_id", Integer, ForeignKey( "post_job_action.id" ), index=True, nullable=False))
387
388Event.table = Table( "event", metadata, 
389    Column( "id", Integer, primary_key=True ),
390    Column( "create_time", DateTime, default=now ),
391    Column( "update_time", DateTime, default=now, onupdate=now ),
392    Column( "history_id", Integer, ForeignKey( "history.id" ), index=True, nullable=True ),
393    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=True ),
394    Column( "message", TrimmedString( 1024 ) ),
395    Column( "session_id", Integer, ForeignKey( "galaxy_session.id" ), index=True, nullable=True ),
396    Column( "tool_id", String( 255 ) ) )
397
398GalaxySession.table = Table( "galaxy_session", metadata,
399    Column( "id", Integer, primary_key=True ),
400    Column( "create_time", DateTime, default=now ),
401    Column( "update_time", DateTime, default=now, onupdate=now ),
402    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=True ),
403    Column( "remote_host", String( 255 ) ),
404    Column( "remote_addr", String( 255 ) ),
405    Column( "referer", TEXT ),
406    Column( "current_history_id", Integer, ForeignKey( "history.id" ), nullable=True ),
407    Column( "session_key", TrimmedString( 255 ), index=True, unique=True ), # unique 128 bit random number coerced to a string
408    Column( "is_valid", Boolean, default=False ),
409    Column( "prev_session_id", Integer ) # saves a reference to the previous session so we have a way to chain them together
410    )
411
412GalaxySessionToHistoryAssociation.table = Table( "galaxy_session_to_history", metadata,
413    Column( "id", Integer, primary_key=True ),
414    Column( "create_time", DateTime, default=now ),
415    Column( "session_id", Integer, ForeignKey( "galaxy_session.id" ), index=True ),
416    Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ) )
417
418StoredWorkflow.table = Table( "stored_workflow", metadata,
419    Column( "id", Integer, primary_key=True ),
420    Column( "create_time", DateTime, default=now ),
421    Column( "update_time", DateTime, default=now, onupdate=now ),
422    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
423    Column( "latest_workflow_id", Integer,
424            ForeignKey( "workflow.id", use_alter=True, name='stored_workflow_latest_workflow_id_fk' ), index=True ),
425    Column( "name", TEXT ),
426    Column( "deleted", Boolean, default=False ),
427    Column( "importable", Boolean, default=False ),
428    Column( "slug", TEXT, index=True ),
429    Column( "published", Boolean, index=True, default=False )
430    )
431
432Workflow.table = Table( "workflow", metadata,
433    Column( "id", Integer, primary_key=True ),
434    Column( "create_time", DateTime, default=now ),
435    Column( "update_time", DateTime, default=now, onupdate=now ),
436    Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True, nullable=False ),
437    Column( "name", TEXT ),
438    Column( "has_cycles", Boolean ),
439    Column( "has_errors", Boolean )
440    )
441
442WorkflowStep.table = Table( "workflow_step", metadata,
443    Column( "id", Integer, primary_key=True ),
444    Column( "create_time", DateTime, default=now ),
445    Column( "update_time", DateTime, default=now, onupdate=now ),
446    Column( "workflow_id", Integer, ForeignKey( "workflow.id" ), index=True, nullable=False ),
447    Column( "type", String(64) ),
448    Column( "tool_id", TEXT ),
449    Column( "tool_version", TEXT ), # Reserved for future
450    Column( "tool_inputs", JSONType ),
451    Column( "tool_errors", JSONType ),
452    Column( "position", JSONType ),
453    Column( "config", JSONType ),
454    Column( "order_index", Integer ),
455    ## Column( "input_connections", JSONType )
456    )
457
458WorkflowStepConnection.table = Table( "workflow_step_connection", metadata,
459    Column( "id", Integer, primary_key=True ),
460    Column( "output_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True ),
461    Column( "input_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True ),
462    Column( "output_name", TEXT ),
463    Column( "input_name", TEXT)
464    )
465
466WorkflowInvocation.table = Table( "workflow_invocation", metadata,
467    Column( "id", Integer, primary_key=True ),
468    Column( "create_time", DateTime, default=now ),
469    Column( "update_time", DateTime, default=now, onupdate=now ),
470    Column( "workflow_id", Integer, ForeignKey( "workflow.id" ), index=True, nullable=False )
471    )
472
473WorkflowInvocationStep.table = Table( "workflow_invocation_step", metadata,
474    Column( "id", Integer, primary_key=True ),
475    Column( "create_time", DateTime, default=now ),
476    Column( "update_time", DateTime, default=now, onupdate=now ),
477    Column( "workflow_invocation_id", Integer, ForeignKey( "workflow_invocation.id" ), index=True, nullable=False ),
478    Column( "workflow_step_id",  Integer, ForeignKey( "workflow_step.id" ), index=True, nullable=False ),
479    Column( "job_id",  Integer, ForeignKey( "job.id" ), index=True, nullable=True )
480    )
481
482StoredWorkflowUserShareAssociation.table = Table( "stored_workflow_user_share_connection", metadata,
483    Column( "id", Integer, primary_key=True ),
484    Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True ),
485    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True )
486    )
487
488StoredWorkflowMenuEntry.table = Table( "stored_workflow_menu_entry", metadata,
489    Column( "id", Integer, primary_key=True ),
490    Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True ),
491    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),                              
492    Column( "order_index", Integer ) )
493
494MetadataFile.table = Table( "metadata_file", metadata, 
495    Column( "id", Integer, primary_key=True ),
496    Column( "name", TEXT ),
497    Column( "hda_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True, nullable=True ),
498    Column( "lda_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), index=True, nullable=True ),
499    Column( "create_time", DateTime, default=now ),
500    Column( "update_time", DateTime, index=True, default=now, onupdate=now ),
501    Column( "deleted", Boolean, index=True, default=False ),
502    Column( "purged", Boolean, index=True, default=False ) )
503
504FormDefinitionCurrent.table = Table('form_definition_current', metadata,
505    Column( "id", Integer, primary_key=True),
506    Column( "create_time", DateTime, default=now ),
507    Column( "update_time", DateTime, default=now, onupdate=now ),
508    Column( "latest_form_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
509    Column( "deleted", Boolean, index=True, default=False ))
510
511FormDefinition.table = Table('form_definition', metadata,
512    Column( "id", Integer, primary_key=True),
513    Column( "create_time", DateTime, default=now ),
514    Column( "update_time", DateTime, default=now, onupdate=now ),
515    Column( "name", TrimmedString( 255 ), nullable=False ),
516    Column( "desc", TEXT ),
517    Column( "form_definition_current_id",
518            Integer, 
519            ForeignKey( "form_definition_current.id", name='for_def_form_def_current_id_fk', use_alter=True ), 
520            index=True ),
521    Column( "fields", JSONType() ),
522    Column( "type", TrimmedString( 255 ), index=True ),
523    Column( "layout", JSONType() ), )
524
525RequestType.table = Table('request_type', metadata,
526    Column( "id", Integer, primary_key=True),
527    Column( "create_time", DateTime, default=now ),
528    Column( "update_time", DateTime, default=now, onupdate=now ),
529    Column( "name", TrimmedString( 255 ), nullable=False ),
530    Column( "desc", TEXT ),
531    Column( "request_form_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
532    Column( "sample_form_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
533    Column( "datatx_info", JSONType() ),
534    Column( "deleted", Boolean, index=True, default=False ) )
535
536RequestTypePermissions.table = Table( "request_type_permissions", metadata,
537    Column( "id", Integer, primary_key=True ),
538    Column( "create_time", DateTime, default=now ),
539    Column( "update_time", DateTime, default=now, onupdate=now ),
540    Column( "action", TEXT ),
541    Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), nullable=True, index=True ),
542    Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
543
544FormValues.table = Table('form_values', metadata,
545    Column( "id", Integer, primary_key=True),
546    Column( "create_time", DateTime, default=now ),
547    Column( "update_time", DateTime, default=now, onupdate=now ),
548    Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
549    Column( "content", JSONType()) )
550
551Request.table = Table('request', metadata,
552    Column( "id", Integer, primary_key=True),
553    Column( "create_time", DateTime, default=now ),
554    Column( "update_time", DateTime, default=now, onupdate=now ),
555    Column( "name", TrimmedString( 255 ), nullable=False ),
556    Column( "desc", TEXT ),
557    Column( "notify", Boolean, default=False ),
558    Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
559    Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), index=True ),
560    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
561    Column( "deleted", Boolean, index=True, default=False ) )
562
563RequestEvent.table = Table('request_event', metadata,
564    Column( "id", Integer, primary_key=True),
565    Column( "create_time", DateTime, default=now ),
566    Column( "update_time", DateTime, default=now, onupdate=now ),
567    Column( "request_id", Integer, ForeignKey( "request.id" ), index=True ), 
568    Column( "state", TrimmedString( 255 ),  index=True ),
569    Column( "comment", TEXT ) )
570
571Sample.table = Table('sample', metadata,
572    Column( "id", Integer, primary_key=True ),
573    Column( "create_time", DateTime, default=now ),
574    Column( "update_time", DateTime, default=now, onupdate=now ),
575    Column( "name", TrimmedString( 255 ), nullable=False ),
576    Column( "desc", TEXT ),
577    Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
578    Column( "request_id", Integer, ForeignKey( "request.id" ), index=True ),
579    Column( "bar_code", TrimmedString( 255 ), index=True ),
580    Column( "library_id", Integer, ForeignKey( "library.id" ), index=True ),
581    Column( "folder_id", Integer, ForeignKey( "library_folder.id" ), index=True ),
582    Column( "deleted", Boolean, index=True, default=False ) )
583
584SampleState.table = Table('sample_state', metadata,
585    Column( "id", Integer, primary_key=True ),
586    Column( "create_time", DateTime, default=now ),
587    Column( "update_time", DateTime, default=now, onupdate=now ),
588    Column( "name", TrimmedString( 255 ), nullable=False ),
589    Column( "desc", TEXT ),
590    Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), index=True ) )
591
592SampleEvent.table = Table('sample_event', metadata,
593    Column( "id", Integer, primary_key=True ),
594    Column( "create_time", DateTime, default=now ),
595    Column( "update_time", DateTime, default=now, onupdate=now ),
596    Column( "sample_id", Integer, ForeignKey( "sample.id" ), index=True ), 
597    Column( "sample_state_id", Integer, ForeignKey( "sample_state.id" ), index=True ), 
598    Column( "comment", TEXT ) )
599
600SampleDataset.table = Table('sample_dataset', metadata,
601    Column( "id", Integer, primary_key=True ),
602    Column( "create_time", DateTime, default=now ),
603    Column( "update_time", DateTime, default=now, onupdate=now ),
604    Column( "sample_id", Integer, ForeignKey( "sample.id" ), index=True ), 
605    Column( "name", TrimmedString( 255 ), nullable=False ),
606    Column( "file_path", TrimmedString( 255 ), nullable=False ),
607    Column( "status", TrimmedString( 255 ), nullable=False ),
608    Column( "error_msg", TEXT ),
609    Column( "size", TrimmedString( 255 ) ) )
610
611Page.table = Table( "page", metadata,
612    Column( "id", Integer, primary_key=True ),
613    Column( "create_time", DateTime, default=now ),
614    Column( "update_time", DateTime, default=now, onupdate=now ),
615    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
616    Column( "latest_revision_id", Integer,
617            ForeignKey( "page_revision.id", use_alter=True, name='page_latest_revision_id_fk' ), index=True ),
618    Column( "title", TEXT ),
619    Column( "slug", TEXT, unique=True, index=True ),
620    Column( "importable", Boolean, index=True, default=False ), 
621    Column( "published", Boolean, index=True, default=False ), 
622    Column( "deleted", Boolean, index=True, default=False ), 
623    )
624
625PageRevision.table = Table( "page_revision", metadata,
626    Column( "id", Integer, primary_key=True ),
627    Column( "create_time", DateTime, default=now ),
628    Column( "update_time", DateTime, default=now, onupdate=now ),
629    Column( "page_id", Integer, ForeignKey( "page.id" ), index=True, nullable=False ),
630    Column( "title", TEXT ),
631    Column( "content", TEXT )
632    )
633
634PageUserShareAssociation.table = Table( "page_user_share_association", metadata,
635    Column( "id", Integer, primary_key=True ),
636    Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ),
637    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True )
638    )
639
640Visualization.table = Table( "visualization", metadata,
641    Column( "id", Integer, primary_key=True ),
642    Column( "create_time", DateTime, default=now ),
643    Column( "update_time", DateTime, default=now, onupdate=now ),
644    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
645    Column( "latest_revision_id", Integer,
646            ForeignKey( "visualization_revision.id", use_alter=True, name='visualization_latest_revision_id_fk' ), index=True ),
647    Column( "title", TEXT ),
648    Column( "type", TEXT ),
649    Column( "dbkey", TEXT, index=True ),
650    Column( "deleted", Boolean, default=False, index=True ),
651    Column( "importable", Boolean, default=False, index=True ),
652    Column( "slug", TEXT, index=True ),
653    Column( "published", Boolean, default=False, index=True )
654    )
655
656VisualizationRevision.table = Table( "visualization_revision", metadata,
657    Column( "id", Integer, primary_key=True ),
658    Column( "create_time", DateTime, default=now ),
659    Column( "update_time", DateTime, default=now, onupdate=now ),
660    Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True, nullable=False ),
661    Column( "title", TEXT ),
662    Column( "dbkey", TEXT, index=True ),
663    Column( "config", JSONType )
664    )
665    
666VisualizationUserShareAssociation.table = Table( "visualization_user_share_association", metadata,
667    Column( "id", Integer, primary_key=True ),
668    Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True ),
669    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True )
670    )
671    
672# Tagging tables.
673
674Tag.table = Table( "tag", metadata,
675    Column( "id", Integer, primary_key=True ),
676    Column( "type", Integer ),
677    Column( "parent_id", Integer, ForeignKey( "tag.id" ) ),
678    Column( "name", TrimmedString(255) ), 
679    UniqueConstraint( "name" ) )
680
681HistoryTagAssociation.table = Table( "history_tag_association", metadata,
682    Column( "id", Integer, primary_key=True ),
683    Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
684    Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
685    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
686    Column( "user_tname", TrimmedString(255), index=True),
687    Column( "value", TrimmedString(255), index=True),
688    Column( "user_value", TrimmedString(255), index=True) )
689    
690DatasetTagAssociation.table = Table( "dataset_tag_association", metadata,
691    Column( "id", Integer, primary_key=True ),
692    Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ),
693    Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
694    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
695    Column( "user_tname", TrimmedString(255), index=True),
696    Column( "value", TrimmedString(255), index=True),
697    Column( "user_value", TrimmedString(255), index=True) )
698
699HistoryDatasetAssociationTagAssociation.table = Table( "history_dataset_association_tag_association", metadata,
700    Column( "id", Integer, primary_key=True ),
701    Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
702    Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
703    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
704    Column( "user_tname", TrimmedString(255), index=True),
705    Column( "value", TrimmedString(255), index=True),
706    Column( "user_value", TrimmedString(255), index=True) )
707        
708StoredWorkflowTagAssociation.table = Table( "stored_workflow_tag_association", metadata,
709    Column( "id", Integer, primary_key=True ),
710    Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True ),
711    Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
712    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
713    Column( "user_tname", Unicode(255), index=True),
714    Column( "value", Unicode(255), index=True),
715    Column( "user_value", Unicode(255), index=True) )
716
717PageTagAssociation.table = Table( "page_tag_association", metadata,
718    Column( "id", Integer, primary_key=True ),
719    Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ),
720    Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
721    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
722    Column( "user_tname", TrimmedString(255), index=True),
723    Column( "value", TrimmedString(255), index=True),
724    Column( "user_value", TrimmedString(255), index=True) )
725    
726WorkflowStepTagAssociation.table = Table( "workflow_step_tag_association", metadata,
727    Column( "id", Integer, primary_key=True ),
728    Column( "workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True ),
729    Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
730    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
731    Column( "user_tname", Unicode(255), index=True),
732    Column( "value", Unicode(255), index=True),
733    Column( "user_value", Unicode(255), index=True) )
734    
735VisualizationTagAssociation.table = Table( "visualization_tag_association", metadata,
736    Column( "id", Integer, primary_key=True ),
737    Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True ),
738    Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
739    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
740    Column( "user_tname", TrimmedString(255), index=True),
741    Column( "value", TrimmedString(255), index=True),
742    Column( "user_value", TrimmedString(255), index=True) )
743    
744# Annotation tables.
745
746HistoryAnnotationAssociation.table = Table( "history_annotation_association", metadata,
747    Column( "id", Integer, primary_key=True ),
748    Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
749    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
750    Column( "annotation", TEXT, index=True) )
751
752HistoryDatasetAssociationAnnotationAssociation.table = Table( "history_dataset_association_annotation_association", metadata,
753    Column( "id", Integer, primary_key=True ),
754    Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
755    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
756    Column( "annotation", TEXT, index=True) )
757
758StoredWorkflowAnnotationAssociation.table = Table( "stored_workflow_annotation_association", metadata,
759    Column( "id", Integer, primary_key=True ),
760    Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True ),
761    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
762    Column( "annotation", TEXT, index=True) )
763
764WorkflowStepAnnotationAssociation.table = Table( "workflow_step_annotation_association", metadata,
765    Column( "id", Integer, primary_key=True ),
766    Column( "workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True ),
767    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
768    Column( "annotation", TEXT, index=True) )
769    
770PageAnnotationAssociation.table = Table( "page_annotation_association", metadata,
771    Column( "id", Integer, primary_key=True ),
772    Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ),
773    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
774    Column( "annotation", TEXT, index=True) )
775    
776VisualizationAnnotationAssociation.table = Table( "visualization_annotation_association", metadata,
777    Column( "id", Integer, primary_key=True ),
778    Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True ),
779    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
780    Column( "annotation", TEXT, index=True) )
781    
782# Ratings tables.
783HistoryRatingAssociation.table = Table( "history_rating_association", metadata,
784    Column( "id", Integer, primary_key=True ),
785    Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
786    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
787    Column( "rating", Integer, index=True) )
788    
789HistoryDatasetAssociationRatingAssociation.table = Table( "history_dataset_association_rating_association", metadata,
790    Column( "id", Integer, primary_key=True ),
791    Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
792    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
793    Column( "rating", Integer, index=True) )
794    
795StoredWorkflowRatingAssociation.table = Table( "stored_workflow_rating_association", metadata,
796    Column( "id", Integer, primary_key=True ),
797    Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True ),
798    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
799    Column( "rating", Integer, index=True) )
800    
801PageRatingAssociation.table = Table( "page_rating_association", metadata,
802    Column( "id", Integer, primary_key=True ),
803    Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ),
804    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
805    Column( "rating", Integer, index=True) )
806    
807VisualizationRatingAssociation.table = Table( "visualization_rating_association", metadata,
808    Column( "id", Integer, primary_key=True ),
809    Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True ),
810    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
811    Column( "rating", Integer, index=True) )
812    
813# User tables.
814    
815UserPreference.table = Table( "user_preference", metadata,
816    Column( "id", Integer, primary_key=True ),
817    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
818    Column( "name", Unicode( 255 ), index=True),
819    Column( "value", Unicode( 1024 ) ) )
820    
821UserAction.table = Table( "user_action", metadata,
822    Column( "id", Integer, primary_key=True ),
823    Column( "create_time", DateTime, default=now ),
824    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
825    Column( "session_id", Integer, ForeignKey( "galaxy_session.id" ), index=True ),
826    Column( "action", Unicode( 255 ) ),
827    Column( "context", Unicode( 512 ) ),
828    Column( "params", Unicode( 1024 ) ) )
829
830APIKeys.table = Table( "api_keys", metadata,
831    Column( "id", Integer, primary_key=True ),
832    Column( "create_time", DateTime, default=now ),
833    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
834    Column( "key", TrimmedString( 32 ), index=True, unique=True ) )
835
836# With the tables defined we can define the mappers and setup the 
837# relationships between the model objects.
838
839assign_mapper( context, Sample, Sample.table,
840               properties=dict( 
841                    events=relation( SampleEvent, backref="sample",
842                        order_by=desc(SampleEvent.table.c.update_time) ),
843                    datasets=relation( SampleDataset, backref="sample",
844                        order_by=desc(SampleDataset.table.c.update_time) ),
845                    values=relation( FormValues,
846                        primaryjoin=( Sample.table.c.form_values_id == FormValues.table.c.id ) ),
847                    request=relation( Request,
848                        primaryjoin=( Sample.table.c.request_id == Request.table.c.id ) ),
849                    folder=relation( LibraryFolder,
850                        primaryjoin=( Sample.table.c.folder_id == LibraryFolder.table.c.id ) ),                 
851                    library=relation( Library,
852                        primaryjoin=( Sample.table.c.library_id == Library.table.c.id ) ),
853            ) )
854
855assign_mapper( context, FormValues, FormValues.table,
856               properties=dict( form_definition=relation( FormDefinition,
857                                                          primaryjoin=( FormValues.table.c.form_definition_id == FormDefinition.table.c.id ) )
858             )
859)
860
861assign_mapper( context, Request, Request.table,
862               properties=dict( values=relation( FormValues,
863                                                 primaryjoin=( Request.table.c.form_values_id == FormValues.table.c.id ) ),
864                                type=relation( RequestType,
865                                               primaryjoin=( Request.table.c.request_type_id == RequestType.table.c.id ) ),
866                                user=relation( User,
867                                               primaryjoin=( Request.table.c.user_id == User.table.c.id ),
868                                               backref="requests" ),
869                                samples=relation( Sample,
870                                                  primaryjoin=( Request.table.c.id == Sample.table.c.request_id ),
871                                                  order_by=asc(Sample.table.c.id) ),
872                                events=relation( RequestEvent, backref="request",
873                                                 order_by=desc(RequestEvent.table.c.update_time) )
874                              ) )
875
876assign_mapper( context, RequestEvent, RequestEvent.table,
877               properties=None )
878
879assign_mapper( context, RequestType, RequestType.table,               
880               properties=dict( states=relation( SampleState, 
881                                                 backref="request_type",
882                                                 primaryjoin=( RequestType.table.c.id == SampleState.table.c.request_type_id ),
883                                                 order_by=asc(SampleState.table.c.update_time) ),
884                                request_form=relation( FormDefinition,
885                                                       primaryjoin=( RequestType.table.c.request_form_id == FormDefinition.table.c.id ) ),
886                                sample_form=relation( FormDefinition,
887                                                      primaryjoin=( RequestType.table.c.sample_form_id == FormDefinition.table.c.id ) ),
888                              ) )
889
890assign_mapper( context, RequestTypePermissions, RequestTypePermissions.table,
891    properties=dict(
892        request_type=relation( RequestType, backref="actions" ),
893        role=relation( Role, backref="request_type_actions" )
894    )
895)
896
897assign_mapper( context, FormDefinition, FormDefinition.table,
898               properties=dict( current=relation( FormDefinitionCurrent,
899                                                  primaryjoin=( FormDefinition.table.c.form_definition_current_id == FormDefinitionCurrent.table.c.id ) )
900                              ) )
901assign_mapper( context, FormDefinitionCurrent, FormDefinitionCurrent.table,
902                properties=dict( forms=relation( FormDefinition, backref='form_definition_current',
903                                                 cascade="all, delete-orphan",
904                                                 primaryjoin=( FormDefinitionCurrent.table.c.id == FormDefinition.table.c.form_definition_current_id ) ),
905                                 latest_form=relation( FormDefinition, post_update=True,
906                                                       primaryjoin=( FormDefinitionCurrent.table.c.latest_form_id == FormDefinition.table.c.id ) )
907                               ) )
908
909as

Large files files are truncated, but you can click here to view the full file