/lib/galaxy/model/mapping.py

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

  1. """
  2. Details of how the data model objects are mapped onto the relational database
  3. are encapsulated here.
  4. """
  5. import logging
  6. log = logging.getLogger( __name__ )
  7. import sys
  8. import datetime
  9. from galaxy.model import *
  10. from galaxy.model.orm import *
  11. from galaxy.model.orm.ext.assignmapper import *
  12. from galaxy.model.custom_types import *
  13. from galaxy.util.bunch import Bunch
  14. from galaxy.security import GalaxyRBACAgent
  15. from sqlalchemy.orm.collections import attribute_mapped_collection
  16. from sqlalchemy.ext.associationproxy import association_proxy
  17. metadata = MetaData()
  18. context = Session = scoped_session( sessionmaker( autoflush=False, autocommit=True ) )
  19. # For backward compatibility with "context.current"
  20. context.current = Session
  21. dialect_to_egg = {
  22. "sqlite" : "pysqlite>=2",
  23. "postgres" : "psycopg2",
  24. "mysql" : "MySQL_python"
  25. }
  26. # NOTE REGARDING TIMESTAMPS:
  27. # It is currently difficult to have the timestamps calculated by the
  28. # database in a portable way, so we're doing it in the client. This
  29. # also saves us from needing to postfetch on postgres. HOWEVER: it
  30. # relies on the client's clock being set correctly, so if clustering
  31. # web servers, use a time server to ensure synchronization
  32. # Return the current time in UTC without any timezone information
  33. now = datetime.datetime.utcnow
  34. User.table = Table( "galaxy_user", metadata,
  35. Column( "id", Integer, primary_key=True),
  36. Column( "create_time", DateTime, default=now ),
  37. Column( "update_time", DateTime, default=now, onupdate=now ),
  38. Column( "email", TrimmedString( 255 ), nullable=False ),
  39. Column( "username", TrimmedString( 255 ), index=True, unique=True ),
  40. Column( "password", TrimmedString( 40 ), nullable=False ),
  41. Column( "external", Boolean, default=False ),
  42. Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
  43. Column( "deleted", Boolean, index=True, default=False ),
  44. Column( "purged", Boolean, index=True, default=False ) )
  45. UserAddress.table = Table( "user_address", metadata,
  46. Column( "id", Integer, primary_key=True),
  47. Column( "create_time", DateTime, default=now ),
  48. Column( "update_time", DateTime, default=now, onupdate=now ),
  49. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  50. Column( "desc", TrimmedString( 255 )),
  51. Column( "name", TrimmedString( 255 ), nullable=False),
  52. Column( "institution", TrimmedString( 255 )),
  53. Column( "address", TrimmedString( 255 ), nullable=False),
  54. Column( "city", TrimmedString( 255 ), nullable=False),
  55. Column( "state", TrimmedString( 255 ), nullable=False),
  56. Column( "postal_code", TrimmedString( 255 ), nullable=False),
  57. Column( "country", TrimmedString( 255 ), nullable=False),
  58. Column( "phone", TrimmedString( 255 )),
  59. Column( "deleted", Boolean, index=True, default=False ),
  60. Column( "purged", Boolean, index=True, default=False ) )
  61. History.table = Table( "history", metadata,
  62. Column( "id", Integer, primary_key=True),
  63. Column( "create_time", DateTime, default=now ),
  64. Column( "update_time", DateTime, index=True, default=now, onupdate=now ),
  65. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  66. Column( "name", TrimmedString( 255 ) ),
  67. Column( "hid_counter", Integer, default=1 ),
  68. Column( "deleted", Boolean, index=True, default=False ),
  69. Column( "purged", Boolean, index=True, default=False ),
  70. Column( "genome_build", TrimmedString( 40 ) ),
  71. Column( "importable", Boolean, default=False ),
  72. Column( "slug", TEXT, index=True ),
  73. Column( "published", Boolean, index=True, default=False ) )
  74. HistoryUserShareAssociation.table = Table( "history_user_share_association", metadata,
  75. Column( "id", Integer, primary_key=True ),
  76. Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
  77. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True )
  78. )
  79. HistoryDatasetAssociation.table = Table( "history_dataset_association", metadata,
  80. Column( "id", Integer, primary_key=True ),
  81. Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
  82. Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ),
  83. Column( "create_time", DateTime, default=now ),
  84. Column( "update_time", DateTime, default=now, onupdate=now ),
  85. Column( "state", TrimmedString( 64 ), index=True, key="_state" ),
  86. Column( "copied_from_history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), nullable=True ),
  87. Column( "copied_from_library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True ),
  88. Column( "hid", Integer ),
  89. Column( "name", TrimmedString( 255 ) ),
  90. Column( "info", TrimmedString( 255 ) ),
  91. Column( "blurb", TrimmedString( 255 ) ),
  92. Column( "peek" , TEXT ),
  93. Column( "extension", TrimmedString( 64 ) ),
  94. Column( "metadata", MetadataType(), key="_metadata" ),
  95. Column( "parent_id", Integer, ForeignKey( "history_dataset_association.id" ), nullable=True ),
  96. Column( "designation", TrimmedString( 255 ) ),
  97. Column( "deleted", Boolean, index=True, default=False ),
  98. Column( "visible", Boolean ) )
  99. Dataset.table = Table( "dataset", metadata,
  100. Column( "id", Integer, primary_key=True ),
  101. Column( "create_time", DateTime, default=now ),
  102. Column( "update_time", DateTime, index=True, default=now, onupdate=now ),
  103. Column( "state", TrimmedString( 64 ), index=True ),
  104. Column( "deleted", Boolean, index=True, default=False ),
  105. Column( "purged", Boolean, index=True, default=False ),
  106. Column( "purgable", Boolean, default=True ),
  107. Column( "external_filename" , TEXT ),
  108. Column( "_extra_files_path", TEXT ),
  109. Column( 'file_size', Numeric( 15, 0 ) ) )
  110. HistoryDatasetAssociationDisplayAtAuthorization.table = Table( "history_dataset_association_display_at_authorization", metadata,
  111. Column( "id", Integer, primary_key=True ),
  112. Column( "create_time", DateTime, default=now ),
  113. Column( "update_time", DateTime, index=True, default=now, onupdate=now ),
  114. Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
  115. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  116. Column( "site", TrimmedString( 255 ) ) )
  117. ImplicitlyConvertedDatasetAssociation.table = Table( "implicitly_converted_dataset_association", metadata,
  118. Column( "id", Integer, primary_key=True ),
  119. Column( "create_time", DateTime, default=now ),
  120. Column( "update_time", DateTime, default=now, onupdate=now ),
  121. Column( "hda_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True, nullable=True ),
  122. Column( "hda_parent_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
  123. Column( "deleted", Boolean, index=True, default=False ),
  124. Column( "metadata_safe", Boolean, index=True, default=True ),
  125. Column( "type", TrimmedString( 255 ) ) )
  126. ValidationError.table = Table( "validation_error", metadata,
  127. Column( "id", Integer, primary_key=True ),
  128. Column( "dataset_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
  129. Column( "message", TrimmedString( 255 ) ),
  130. Column( "err_type", TrimmedString( 64 ) ),
  131. Column( "attributes", TEXT ) )
  132. Group.table = Table( "galaxy_group", 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( "name", String( 255 ), index=True, unique=True ),
  137. Column( "deleted", Boolean, index=True, default=False ) )
  138. UserGroupAssociation.table = Table( "user_group_association", metadata,
  139. Column( "id", Integer, primary_key=True ),
  140. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  141. Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),
  142. Column( "create_time", DateTime, default=now ),
  143. Column( "update_time", DateTime, default=now, onupdate=now ) )
  144. UserRoleAssociation.table = Table( "user_role_association", metadata,
  145. Column( "id", Integer, primary_key=True ),
  146. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  147. Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ),
  148. Column( "create_time", DateTime, default=now ),
  149. Column( "update_time", DateTime, default=now, onupdate=now ) )
  150. GroupRoleAssociation.table = Table( "group_role_association", metadata,
  151. Column( "id", Integer, primary_key=True ),
  152. Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ),
  153. Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ),
  154. Column( "create_time", DateTime, default=now ),
  155. Column( "update_time", DateTime, default=now, onupdate=now ) )
  156. Role.table = Table( "role", metadata,
  157. Column( "id", Integer, primary_key=True ),
  158. Column( "create_time", DateTime, default=now ),
  159. Column( "update_time", DateTime, default=now, onupdate=now ),
  160. Column( "name", String( 255 ), index=True, unique=True ),
  161. Column( "description", TEXT ),
  162. Column( "type", String( 40 ), index=True ),
  163. Column( "deleted", Boolean, index=True, default=False ) )
  164. DatasetPermissions.table = Table( "dataset_permissions", metadata,
  165. Column( "id", Integer, primary_key=True ),
  166. Column( "create_time", DateTime, default=now ),
  167. Column( "update_time", DateTime, default=now, onupdate=now ),
  168. Column( "action", TEXT ),
  169. Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ),
  170. Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
  171. LibraryPermissions.table = Table( "library_permissions", metadata,
  172. Column( "id", Integer, primary_key=True ),
  173. Column( "create_time", DateTime, default=now ),
  174. Column( "update_time", DateTime, default=now, onupdate=now ),
  175. Column( "action", TEXT ),
  176. Column( "library_id", Integer, ForeignKey( "library.id" ), nullable=True, index=True ),
  177. Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
  178. LibraryFolderPermissions.table = Table( "library_folder_permissions", metadata,
  179. Column( "id", Integer, primary_key=True ),
  180. Column( "create_time", DateTime, default=now ),
  181. Column( "update_time", DateTime, default=now, onupdate=now ),
  182. Column( "action", TEXT ),
  183. Column( "library_folder_id", Integer, ForeignKey( "library_folder.id" ), nullable=True, index=True ),
  184. Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
  185. LibraryDatasetPermissions.table = Table( "library_dataset_permissions", metadata,
  186. Column( "id", Integer, primary_key=True ),
  187. Column( "create_time", DateTime, default=now ),
  188. Column( "update_time", DateTime, default=now, onupdate=now ),
  189. Column( "action", TEXT ),
  190. Column( "library_dataset_id", Integer, ForeignKey( "library_dataset.id" ), nullable=True, index=True ),
  191. Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
  192. LibraryDatasetDatasetAssociationPermissions.table = Table( "library_dataset_dataset_association_permissions", metadata,
  193. Column( "id", Integer, primary_key=True ),
  194. Column( "create_time", DateTime, default=now ),
  195. Column( "update_time", DateTime, default=now, onupdate=now ),
  196. Column( "action", TEXT ),
  197. Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True, index=True ),
  198. Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
  199. DefaultUserPermissions.table = Table( "default_user_permissions", metadata,
  200. Column( "id", Integer, primary_key=True ),
  201. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  202. Column( "action", TEXT ),
  203. Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
  204. DefaultHistoryPermissions.table = Table( "default_history_permissions", metadata,
  205. Column( "id", Integer, primary_key=True ),
  206. Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
  207. Column( "action", TEXT ),
  208. Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
  209. LibraryDataset.table = Table( "library_dataset", metadata,
  210. Column( "id", Integer, primary_key=True ),
  211. 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
  212. Column( "folder_id", Integer, ForeignKey( "library_folder.id" ), index=True ),
  213. Column( "order_id", Integer ), #not currently being used, but for possible future use
  214. Column( "create_time", DateTime, default=now ),
  215. Column( "update_time", DateTime, default=now, onupdate=now ),
  216. 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?)
  217. Column( "info", TrimmedString( 255 ), key="_info" ), #when not None/null this will supercede display in library (but not when imported into user's history?)
  218. Column( "deleted", Boolean, index=True, default=False ) )
  219. LibraryDatasetDatasetAssociation.table = Table( "library_dataset_dataset_association", metadata,
  220. Column( "id", Integer, primary_key=True ),
  221. Column( "library_dataset_id", Integer, ForeignKey( "library_dataset.id" ), index=True ),
  222. Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ),
  223. Column( "create_time", DateTime, default=now ),
  224. Column( "update_time", DateTime, default=now, onupdate=now ),
  225. Column( "state", TrimmedString( 64 ), index=True, key="_state" ),
  226. 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 ),
  227. 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 ),
  228. Column( "name", TrimmedString( 255 ), index=True ),
  229. Column( "info", TrimmedString( 255 ) ),
  230. Column( "blurb", TrimmedString( 255 ) ),
  231. Column( "peek" , TEXT ),
  232. Column( "extension", TrimmedString( 64 ) ),
  233. Column( "metadata", MetadataType(), key="_metadata" ),
  234. Column( "parent_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True ),
  235. Column( "designation", TrimmedString( 255 ) ),
  236. Column( "deleted", Boolean, index=True, default=False ),
  237. Column( "visible", Boolean ),
  238. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  239. Column( "message", TrimmedString( 255 ) ) )
  240. Library.table = Table( "library", metadata,
  241. Column( "id", Integer, primary_key=True ),
  242. Column( "root_folder_id", Integer, ForeignKey( "library_folder.id" ), index=True ),
  243. Column( "create_time", DateTime, default=now ),
  244. Column( "update_time", DateTime, default=now, onupdate=now ),
  245. Column( "name", String( 255 ), index=True ),
  246. Column( "deleted", Boolean, index=True, default=False ),
  247. Column( "purged", Boolean, index=True, default=False ),
  248. Column( "description", TEXT ),
  249. Column( "synopsis", TEXT ) )
  250. LibraryFolder.table = Table( "library_folder", metadata,
  251. Column( "id", Integer, primary_key=True ),
  252. Column( "parent_id", Integer, ForeignKey( "library_folder.id" ), nullable = True, index=True ),
  253. Column( "create_time", DateTime, default=now ),
  254. Column( "update_time", DateTime, default=now, onupdate=now ),
  255. Column( "name", TEXT, index=True ),
  256. Column( "description", TEXT ),
  257. Column( "order_id", Integer ), #not currently being used, but for possible future use
  258. Column( "item_count", Integer ),
  259. Column( "deleted", Boolean, index=True, default=False ),
  260. Column( "purged", Boolean, index=True, default=False ),
  261. Column( "genome_build", TrimmedString( 40 ) ) )
  262. LibraryInfoAssociation.table = Table( 'library_info_association', metadata,
  263. Column( "id", Integer, primary_key=True ),
  264. Column( "library_id", Integer, ForeignKey( "library.id" ), index=True ),
  265. Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
  266. Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
  267. Column( "inheritable", Boolean, index=True, default=False ),
  268. Column( "deleted", Boolean, index=True, default=False ) )
  269. LibraryFolderInfoAssociation.table = Table( 'library_folder_info_association', metadata,
  270. Column( "id", Integer, primary_key=True ),
  271. Column( "library_folder_id", Integer, ForeignKey( "library_folder.id" ), nullable=True, index=True ),
  272. Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
  273. Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
  274. Column( "inheritable", Boolean, index=True, default=False ),
  275. Column( "deleted", Boolean, index=True, default=False ) )
  276. LibraryDatasetDatasetInfoAssociation.table = Table( 'library_dataset_dataset_info_association', metadata,
  277. Column( "id", Integer, primary_key=True ),
  278. Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True, index=True ),
  279. Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
  280. Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
  281. Column( "deleted", Boolean, index=True, default=False ) )
  282. Job.table = Table( "job", metadata,
  283. Column( "id", Integer, primary_key=True ),
  284. Column( "create_time", DateTime, default=now ),
  285. Column( "update_time", DateTime, default=now, onupdate=now ),
  286. Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
  287. Column( "library_folder_id", Integer, ForeignKey( "library_folder.id" ), index=True ),
  288. Column( "tool_id", String( 255 ) ),
  289. Column( "tool_version", TEXT, default="1.0.0" ),
  290. Column( "state", String( 64 ), index=True ),
  291. Column( "info", TrimmedString( 255 ) ),
  292. Column( "command_line", TEXT ),
  293. Column( "param_filename", String( 1024 ) ),
  294. Column( "runner_name", String( 255 ) ),
  295. Column( "stdout", TEXT ),
  296. Column( "stderr", TEXT ),
  297. Column( "traceback", TEXT ),
  298. Column( "session_id", Integer, ForeignKey( "galaxy_session.id" ), index=True, nullable=True ),
  299. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=True ),
  300. Column( "job_runner_name", String( 255 ) ),
  301. Column( "job_runner_external_id", String( 255 ) ),
  302. Column( "imported", Boolean, default=False, index=True ) )
  303. JobParameter.table = Table( "job_parameter", metadata,
  304. Column( "id", Integer, primary_key=True ),
  305. Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
  306. Column( "name", String(255) ),
  307. Column( "value", TEXT ) )
  308. JobToInputDatasetAssociation.table = Table( "job_to_input_dataset", metadata,
  309. Column( "id", Integer, primary_key=True ),
  310. Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
  311. Column( "dataset_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
  312. Column( "name", String(255) ) )
  313. JobToOutputDatasetAssociation.table = Table( "job_to_output_dataset", metadata,
  314. Column( "id", Integer, primary_key=True ),
  315. Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
  316. Column( "dataset_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
  317. Column( "name", String(255) ) )
  318. JobToOutputLibraryDatasetAssociation.table = Table( "job_to_output_library_dataset", metadata,
  319. Column( "id", Integer, primary_key=True ),
  320. Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
  321. Column( "ldda_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), index=True ),
  322. Column( "name", String(255) ) )
  323. JobExternalOutputMetadata.table = Table( "job_external_output_metadata", metadata,
  324. Column( "id", Integer, primary_key=True ),
  325. Column( "job_id", Integer, ForeignKey( "job.id" ), index=True ),
  326. Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True, nullable=True ),
  327. Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), index=True, nullable=True ),
  328. Column( "filename_in", String( 255 ) ),
  329. Column( "filename_out", String( 255 ) ),
  330. Column( "filename_results_code", String( 255 ) ),
  331. Column( "filename_kwds", String( 255 ) ),
  332. Column( "filename_override_metadata", String( 255 ) ),
  333. Column( "job_runner_external_pid", String( 255 ) ) )
  334. PostJobAction.table = Table("post_job_action", metadata,
  335. Column("id", Integer, primary_key=True),
  336. Column("workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True, nullable=False),
  337. Column("action_type", String(255), nullable=False),
  338. Column("output_name", String(255), nullable=True),
  339. Column("action_arguments", JSONType, nullable=True))
  340. PostJobActionAssociation.table = Table("post_job_action_association", metadata,
  341. Column("id", Integer, primary_key=True),
  342. Column("job_id", Integer, ForeignKey( "job.id" ), index=True, nullable=False),
  343. Column("post_job_action_id", Integer, ForeignKey( "post_job_action.id" ), index=True, nullable=False))
  344. Event.table = Table( "event", metadata,
  345. Column( "id", Integer, primary_key=True ),
  346. Column( "create_time", DateTime, default=now ),
  347. Column( "update_time", DateTime, default=now, onupdate=now ),
  348. Column( "history_id", Integer, ForeignKey( "history.id" ), index=True, nullable=True ),
  349. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=True ),
  350. Column( "message", TrimmedString( 1024 ) ),
  351. Column( "session_id", Integer, ForeignKey( "galaxy_session.id" ), index=True, nullable=True ),
  352. Column( "tool_id", String( 255 ) ) )
  353. GalaxySession.table = Table( "galaxy_session", metadata,
  354. Column( "id", Integer, primary_key=True ),
  355. Column( "create_time", DateTime, default=now ),
  356. Column( "update_time", DateTime, default=now, onupdate=now ),
  357. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=True ),
  358. Column( "remote_host", String( 255 ) ),
  359. Column( "remote_addr", String( 255 ) ),
  360. Column( "referer", TEXT ),
  361. Column( "current_history_id", Integer, ForeignKey( "history.id" ), nullable=True ),
  362. Column( "session_key", TrimmedString( 255 ), index=True, unique=True ), # unique 128 bit random number coerced to a string
  363. Column( "is_valid", Boolean, default=False ),
  364. Column( "prev_session_id", Integer ) # saves a reference to the previous session so we have a way to chain them together
  365. )
  366. GalaxySessionToHistoryAssociation.table = Table( "galaxy_session_to_history", metadata,
  367. Column( "id", Integer, primary_key=True ),
  368. Column( "create_time", DateTime, default=now ),
  369. Column( "session_id", Integer, ForeignKey( "galaxy_session.id" ), index=True ),
  370. Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ) )
  371. StoredWorkflow.table = Table( "stored_workflow", metadata,
  372. Column( "id", Integer, primary_key=True ),
  373. Column( "create_time", DateTime, default=now ),
  374. Column( "update_time", DateTime, default=now, onupdate=now ),
  375. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
  376. Column( "latest_workflow_id", Integer,
  377. ForeignKey( "workflow.id", use_alter=True, name='stored_workflow_latest_workflow_id_fk' ), index=True ),
  378. Column( "name", TEXT ),
  379. Column( "deleted", Boolean, default=False ),
  380. Column( "importable", Boolean, default=False ),
  381. Column( "slug", TEXT, index=True ),
  382. Column( "published", Boolean, index=True, default=False )
  383. )
  384. Workflow.table = Table( "workflow", metadata,
  385. Column( "id", Integer, primary_key=True ),
  386. Column( "create_time", DateTime, default=now ),
  387. Column( "update_time", DateTime, default=now, onupdate=now ),
  388. Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True, nullable=False ),
  389. Column( "name", TEXT ),
  390. Column( "has_cycles", Boolean ),
  391. Column( "has_errors", Boolean )
  392. )
  393. WorkflowStep.table = Table( "workflow_step", metadata,
  394. Column( "id", Integer, primary_key=True ),
  395. Column( "create_time", DateTime, default=now ),
  396. Column( "update_time", DateTime, default=now, onupdate=now ),
  397. Column( "workflow_id", Integer, ForeignKey( "workflow.id" ), index=True, nullable=False ),
  398. Column( "type", String(64) ),
  399. Column( "tool_id", TEXT ),
  400. Column( "tool_version", TEXT ), # Reserved for future
  401. Column( "tool_inputs", JSONType ),
  402. Column( "tool_errors", JSONType ),
  403. Column( "position", JSONType ),
  404. Column( "config", JSONType ),
  405. Column( "order_index", Integer ),
  406. ## Column( "input_connections", JSONType )
  407. )
  408. WorkflowStepConnection.table = Table( "workflow_step_connection", metadata,
  409. Column( "id", Integer, primary_key=True ),
  410. Column( "output_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True ),
  411. Column( "input_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True ),
  412. Column( "output_name", TEXT ),
  413. Column( "input_name", TEXT)
  414. )
  415. WorkflowInvocation.table = Table( "workflow_invocation", metadata,
  416. Column( "id", Integer, primary_key=True ),
  417. Column( "create_time", DateTime, default=now ),
  418. Column( "update_time", DateTime, default=now, onupdate=now ),
  419. Column( "workflow_id", Integer, ForeignKey( "workflow.id" ), index=True, nullable=False )
  420. )
  421. WorkflowInvocationStep.table = Table( "workflow_invocation_step", metadata,
  422. Column( "id", Integer, primary_key=True ),
  423. Column( "create_time", DateTime, default=now ),
  424. Column( "update_time", DateTime, default=now, onupdate=now ),
  425. Column( "workflow_invocation_id", Integer, ForeignKey( "workflow_invocation.id" ), index=True, nullable=False ),
  426. Column( "workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True, nullable=False ),
  427. Column( "job_id", Integer, ForeignKey( "job.id" ), index=True, nullable=True )
  428. )
  429. StoredWorkflowUserShareAssociation.table = Table( "stored_workflow_user_share_connection", metadata,
  430. Column( "id", Integer, primary_key=True ),
  431. Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True ),
  432. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True )
  433. )
  434. StoredWorkflowMenuEntry.table = Table( "stored_workflow_menu_entry", metadata,
  435. Column( "id", Integer, primary_key=True ),
  436. Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True ),
  437. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  438. Column( "order_index", Integer ) )
  439. MetadataFile.table = Table( "metadata_file", metadata,
  440. Column( "id", Integer, primary_key=True ),
  441. Column( "name", TEXT ),
  442. Column( "hda_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True, nullable=True ),
  443. Column( "lda_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), index=True, nullable=True ),
  444. Column( "create_time", DateTime, default=now ),
  445. Column( "update_time", DateTime, index=True, default=now, onupdate=now ),
  446. Column( "deleted", Boolean, index=True, default=False ),
  447. Column( "purged", Boolean, index=True, default=False ) )
  448. FormDefinitionCurrent.table = Table('form_definition_current', metadata,
  449. Column( "id", Integer, primary_key=True),
  450. Column( "create_time", DateTime, default=now ),
  451. Column( "update_time", DateTime, default=now, onupdate=now ),
  452. Column( "latest_form_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
  453. Column( "deleted", Boolean, index=True, default=False ))
  454. FormDefinition.table = Table('form_definition', metadata,
  455. Column( "id", Integer, primary_key=True),
  456. Column( "create_time", DateTime, default=now ),
  457. Column( "update_time", DateTime, default=now, onupdate=now ),
  458. Column( "name", TrimmedString( 255 ), nullable=False ),
  459. Column( "desc", TEXT ),
  460. Column( "form_definition_current_id",
  461. Integer,
  462. ForeignKey( "form_definition_current.id", name='for_def_form_def_current_id_fk', use_alter=True ),
  463. index=True ),
  464. Column( "fields", JSONType() ),
  465. Column( "type", TrimmedString( 255 ), index=True ),
  466. Column( "layout", JSONType() ), )
  467. RequestType.table = Table('request_type', metadata,
  468. Column( "id", Integer, primary_key=True),
  469. Column( "create_time", DateTime, default=now ),
  470. Column( "update_time", DateTime, default=now, onupdate=now ),
  471. Column( "name", TrimmedString( 255 ), nullable=False ),
  472. Column( "desc", TEXT ),
  473. Column( "request_form_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
  474. Column( "sample_form_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
  475. Column( "datatx_info", JSONType() ),
  476. Column( "deleted", Boolean, index=True, default=False ) )
  477. RequestTypePermissions.table = Table( "request_type_permissions", metadata,
  478. Column( "id", Integer, primary_key=True ),
  479. Column( "create_time", DateTime, default=now ),
  480. Column( "update_time", DateTime, default=now, onupdate=now ),
  481. Column( "action", TEXT ),
  482. Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), nullable=True, index=True ),
  483. Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) )
  484. FormValues.table = Table('form_values', metadata,
  485. Column( "id", Integer, primary_key=True),
  486. Column( "create_time", DateTime, default=now ),
  487. Column( "update_time", DateTime, default=now, onupdate=now ),
  488. Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ),
  489. Column( "content", JSONType()) )
  490. Request.table = Table('request', metadata,
  491. Column( "id", Integer, primary_key=True),
  492. Column( "create_time", DateTime, default=now ),
  493. Column( "update_time", DateTime, default=now, onupdate=now ),
  494. Column( "name", TrimmedString( 255 ), nullable=False ),
  495. Column( "desc", TEXT ),
  496. Column( "notify", Boolean, default=False ),
  497. Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
  498. Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), index=True ),
  499. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  500. Column( "deleted", Boolean, index=True, default=False ) )
  501. RequestEvent.table = Table('request_event', metadata,
  502. Column( "id", Integer, primary_key=True),
  503. Column( "create_time", DateTime, default=now ),
  504. Column( "update_time", DateTime, default=now, onupdate=now ),
  505. Column( "request_id", Integer, ForeignKey( "request.id" ), index=True ),
  506. Column( "state", TrimmedString( 255 ), index=True ),
  507. Column( "comment", TEXT ) )
  508. Sample.table = Table('sample', metadata,
  509. Column( "id", Integer, primary_key=True ),
  510. Column( "create_time", DateTime, default=now ),
  511. Column( "update_time", DateTime, default=now, onupdate=now ),
  512. Column( "name", TrimmedString( 255 ), nullable=False ),
  513. Column( "desc", TEXT ),
  514. Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ),
  515. Column( "request_id", Integer, ForeignKey( "request.id" ), index=True ),
  516. Column( "bar_code", TrimmedString( 255 ), index=True ),
  517. Column( "library_id", Integer, ForeignKey( "library.id" ), index=True ),
  518. Column( "folder_id", Integer, ForeignKey( "library_folder.id" ), index=True ),
  519. Column( "deleted", Boolean, index=True, default=False ) )
  520. SampleState.table = Table('sample_state', metadata,
  521. Column( "id", Integer, primary_key=True ),
  522. Column( "create_time", DateTime, default=now ),
  523. Column( "update_time", DateTime, default=now, onupdate=now ),
  524. Column( "name", TrimmedString( 255 ), nullable=False ),
  525. Column( "desc", TEXT ),
  526. Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), index=True ) )
  527. SampleEvent.table = Table('sample_event', metadata,
  528. Column( "id", Integer, primary_key=True ),
  529. Column( "create_time", DateTime, default=now ),
  530. Column( "update_time", DateTime, default=now, onupdate=now ),
  531. Column( "sample_id", Integer, ForeignKey( "sample.id" ), index=True ),
  532. Column( "sample_state_id", Integer, ForeignKey( "sample_state.id" ), index=True ),
  533. Column( "comment", TEXT ) )
  534. SampleDataset.table = Table('sample_dataset', metadata,
  535. Column( "id", Integer, primary_key=True ),
  536. Column( "create_time", DateTime, default=now ),
  537. Column( "update_time", DateTime, default=now, onupdate=now ),
  538. Column( "sample_id", Integer, ForeignKey( "sample.id" ), index=True ),
  539. Column( "name", TrimmedString( 255 ), nullable=False ),
  540. Column( "file_path", TrimmedString( 255 ), nullable=False ),
  541. Column( "status", TrimmedString( 255 ), nullable=False ),
  542. Column( "error_msg", TEXT ),
  543. Column( "size", TrimmedString( 255 ) ) )
  544. Page.table = Table( "page", 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( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
  549. Column( "latest_revision_id", Integer,
  550. ForeignKey( "page_revision.id", use_alter=True, name='page_latest_revision_id_fk' ), index=True ),
  551. Column( "title", TEXT ),
  552. Column( "slug", TEXT, unique=True, index=True ),
  553. Column( "importable", Boolean, index=True, default=False ),
  554. Column( "published", Boolean, index=True, default=False ),
  555. Column( "deleted", Boolean, index=True, default=False ),
  556. )
  557. PageRevision.table = Table( "page_revision", metadata,
  558. Column( "id", Integer, primary_key=True ),
  559. Column( "create_time", DateTime, default=now ),
  560. Column( "update_time", DateTime, default=now, onupdate=now ),
  561. Column( "page_id", Integer, ForeignKey( "page.id" ), index=True, nullable=False ),
  562. Column( "title", TEXT ),
  563. Column( "content", TEXT )
  564. )
  565. PageUserShareAssociation.table = Table( "page_user_share_association", metadata,
  566. Column( "id", Integer, primary_key=True ),
  567. Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ),
  568. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True )
  569. )
  570. Visualization.table = Table( "visualization", metadata,
  571. Column( "id", Integer, primary_key=True ),
  572. Column( "create_time", DateTime, default=now ),
  573. Column( "update_time", DateTime, default=now, onupdate=now ),
  574. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
  575. Column( "latest_revision_id", Integer,
  576. ForeignKey( "visualization_revision.id", use_alter=True, name='visualization_latest_revision_id_fk' ), index=True ),
  577. Column( "title", TEXT ),
  578. Column( "type", TEXT ),
  579. Column( "dbkey", TEXT, index=True ),
  580. Column( "deleted", Boolean, default=False, index=True ),
  581. Column( "importable", Boolean, default=False, index=True ),
  582. Column( "slug", TEXT, index=True ),
  583. Column( "published", Boolean, default=False, index=True )
  584. )
  585. VisualizationRevision.table = Table( "visualization_revision", metadata,
  586. Column( "id", Integer, primary_key=True ),
  587. Column( "create_time", DateTime, default=now ),
  588. Column( "update_time", DateTime, default=now, onupdate=now ),
  589. Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True, nullable=False ),
  590. Column( "title", TEXT ),
  591. Column( "dbkey", TEXT, index=True ),
  592. Column( "config", JSONType )
  593. )
  594. VisualizationUserShareAssociation.table = Table( "visualization_user_share_association", metadata,
  595. Column( "id", Integer, primary_key=True ),
  596. Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True ),
  597. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True )
  598. )
  599. # Tagging tables.
  600. Tag.table = Table( "tag", metadata,
  601. Column( "id", Integer, primary_key=True ),
  602. Column( "type", Integer ),
  603. Column( "parent_id", Integer, ForeignKey( "tag.id" ) ),
  604. Column( "name", TrimmedString(255) ),
  605. UniqueConstraint( "name" ) )
  606. HistoryTagAssociation.table = Table( "history_tag_association", metadata,
  607. Column( "id", Integer, primary_key=True ),
  608. Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
  609. Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
  610. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  611. Column( "user_tname", TrimmedString(255), index=True),
  612. Column( "value", TrimmedString(255), index=True),
  613. Column( "user_value", TrimmedString(255), index=True) )
  614. DatasetTagAssociation.table = Table( "dataset_tag_association", metadata,
  615. Column( "id", Integer, primary_key=True ),
  616. Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ),
  617. Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
  618. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  619. Column( "user_tname", TrimmedString(255), index=True),
  620. Column( "value", TrimmedString(255), index=True),
  621. Column( "user_value", TrimmedString(255), index=True) )
  622. HistoryDatasetAssociationTagAssociation.table = Table( "history_dataset_association_tag_association", metadata,
  623. Column( "id", Integer, primary_key=True ),
  624. Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
  625. Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
  626. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  627. Column( "user_tname", TrimmedString(255), index=True),
  628. Column( "value", TrimmedString(255), index=True),
  629. Column( "user_value", TrimmedString(255), index=True) )
  630. StoredWorkflowTagAssociation.table = Table( "stored_workflow_tag_association", metadata,
  631. Column( "id", Integer, primary_key=True ),
  632. Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True ),
  633. Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
  634. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  635. Column( "user_tname", Unicode(255), index=True),
  636. Column( "value", Unicode(255), index=True),
  637. Column( "user_value", Unicode(255), index=True) )
  638. PageTagAssociation.table = Table( "page_tag_association", metadata,
  639. Column( "id", Integer, primary_key=True ),
  640. Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ),
  641. Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
  642. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  643. Column( "user_tname", TrimmedString(255), index=True),
  644. Column( "value", TrimmedString(255), index=True),
  645. Column( "user_value", TrimmedString(255), index=True) )
  646. WorkflowStepTagAssociation.table = Table( "workflow_step_tag_association", metadata,
  647. Column( "id", Integer, primary_key=True ),
  648. Column( "workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True ),
  649. Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
  650. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  651. Column( "user_tname", Unicode(255), index=True),
  652. Column( "value", Unicode(255), index=True),
  653. Column( "user_value", Unicode(255), index=True) )
  654. VisualizationTagAssociation.table = Table( "visualization_tag_association", metadata,
  655. Column( "id", Integer, primary_key=True ),
  656. Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True ),
  657. Column( "tag_id", Integer, ForeignKey( "tag.id" ), index=True ),
  658. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  659. Column( "user_tname", TrimmedString(255), index=True),
  660. Column( "value", TrimmedString(255), index=True),
  661. Column( "user_value", TrimmedString(255), index=True) )
  662. # Annotation tables.
  663. HistoryAnnotationAssociation.table = Table( "history_annotation_association", metadata,
  664. Column( "id", Integer, primary_key=True ),
  665. Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
  666. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  667. Column( "annotation", TEXT, index=True) )
  668. HistoryDatasetAssociationAnnotationAssociation.table = Table( "history_dataset_association_annotation_association", metadata,
  669. Column( "id", Integer, primary_key=True ),
  670. Column( "history_dataset_association_id", Integer, ForeignKey( "history_dataset_association.id" ), index=True ),
  671. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  672. Column( "annotation", TEXT, index=True) )
  673. StoredWorkflowAnnotationAssociation.table = Table( "stored_workflow_annotation_association", metadata,
  674. Column( "id", Integer, primary_key=True ),
  675. Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True ),
  676. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  677. Column( "annotation", TEXT, index=True) )
  678. WorkflowStepAnnotationAssociation.table = Table( "workflow_step_annotation_association", metadata,
  679. Column( "id", Integer, primary_key=True ),
  680. Column( "workflow_step_id", Integer, ForeignKey( "workflow_step.id" ), index=True ),
  681. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  682. Column( "annotation", TEXT, index=True) )
  683. PageAnnotationAssociation.table = Table( "page_annotation_association", metadata,
  684. Column( "id", Integer, primary_key=True ),
  685. Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ),
  686. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  687. Column( "annotation", TEXT, index=True) )
  688. VisualizationAnnotationAssociation.table = Table( "visualization_annotation_association", metadata,
  689. Column( "id", Integer, primary_key=True ),
  690. Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True ),
  691. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  692. Column( "annotation", TEXT, index=True) )
  693. # Ratings tables.
  694. HistoryRatingAssociation.table = Table( "history_rating_association", metadata,
  695. Column( "id", Integer, primary_key=True ),
  696. Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ),
  697. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  698. Column( "rating", Integer, index=True) )
  699. HistoryDatasetAssociationRatingAssociation.table = Table( "history_dataset_association_rating_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( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  703. Column( "rating", Integer, index=True) )
  704. StoredWorkflowRatingAssociation.table = Table( "stored_workflow_rating_association", metadata,
  705. Column( "id", Integer, primary_key=True ),
  706. Column( "stored_workflow_id", Integer, ForeignKey( "stored_workflow.id" ), index=True ),
  707. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  708. Column( "rating", Integer, index=True) )
  709. PageRatingAssociation.table = Table( "page_rating_association", metadata,
  710. Column( "id", Integer, primary_key=True ),
  711. Column( "page_id", Integer, ForeignKey( "page.id" ), index=True ),
  712. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  713. Column( "rating", Integer, index=True) )
  714. VisualizationRatingAssociation.table = Table( "visualization_rating_association", metadata,
  715. Column( "id", Integer, primary_key=True ),
  716. Column( "visualization_id", Integer, ForeignKey( "visualization.id" ), index=True ),
  717. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  718. Column( "rating", Integer, index=True) )
  719. # User tables.
  720. UserPreference.table = Table( "user_preference", metadata,
  721. Column( "id", Integer, primary_key=True ),
  722. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  723. Column( "name", Unicode( 255 ), index=True),
  724. Column( "value", Unicode( 1024 ) ) )
  725. UserAction.table = Table( "user_action", metadata,
  726. Column( "id", Integer, primary_key=True ),
  727. Column( "create_time", DateTime, default=now ),
  728. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  729. Column( "session_id", Integer, ForeignKey( "galaxy_session.id" ), index=True ),
  730. Column( "action", Unicode( 255 ) ),
  731. Column( "context", Unicode( 512 ) ),
  732. Column( "params", Unicode( 1024 ) ) )
  733. APIKeys.table = Table( "api_keys", metadata,
  734. Column( "id", Integer, primary_key=True ),
  735. Column( "create_time", DateTime, default=now ),
  736. Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ),
  737. Column( "key", TrimmedString( 32 ), index=True, unique=True ) )
  738. # With the tables defined we can define the mappers and setup the
  739. # relationships between the model objects.
  740. assign_mapper( context, Sample, Sample.table,
  741. properties=dict(
  742. events=relation( SampleEvent, backref="sample",
  743. order_by=desc(SampleEvent.table.c.update_time) ),
  744. datasets=relation( SampleDataset, backref="sample",
  745. order_by=desc(SampleDataset.table.c.update_time) ),
  746. values=relation( FormValues,
  747. primaryjoin=( Sample.table.c.form_values_id == FormValues.table.c.id ) ),
  748. request=relation( Request,
  749. primaryjoin=( Sample.table.c.request_id == Request.table.c.id ) ),
  750. folder=relation( LibraryFolder,
  751. primaryjoin=( Sample.table.c.folder_id == LibraryFolder.table.c.id ) ),
  752. library=relation( Library,
  753. primaryjoin=( Sample.table.c.library_id == Library.table.c.id ) ),
  754. ) )
  755. assign_mapper( context, FormValues, FormValues.table,
  756. properties=dict( form_definition=relation( FormDefinition,
  757. primaryjoin=( FormValues.table.c.form_definition_id == FormDefinition.table.c.id ) )
  758. )
  759. )
  760. assign_mapper( context, Request, Request.table,
  761. properties=dict( values=relation( FormValues,
  762. primaryjoin=( Request.table.c.form_values_id == FormValues.table.c.id ) ),
  763. type=relation( RequestType,
  764. primaryjoin=( Request.table.c.request_type_id == RequestType.table.c.id ) ),
  765. user=relation( User,
  766. primaryjoin=( Request.table.c.user_id == User.table.c.id ),
  767. backref="requests" ),
  768. samples=relation( Sample,
  769. primaryjoin=( Request.table.c.id == Sample.table.c.request_id ),
  770. order_by=asc(Sample.table.c.id) ),
  771. events=relation( RequestEvent, backref="request",
  772. order_by=desc(RequestEvent.table.c.update_time) )
  773. ) )
  774. assign_mapper( context, RequestEvent, RequestEvent.table,
  775. properties=None )
  776. assign_mapper( context, RequestType, RequestType.table,
  777. properties=dict( states=relation( SampleState,
  778. backref="request_type",
  779. primaryjoin=( RequestType.table.c.id == SampleState.table.c.request_type_id ),
  780. order_by=asc(SampleState.table.c.update_time) ),
  781. request_form=relation( FormDefinition,
  782. primaryjoin=( RequestType.table.c.request_form_id == FormDefinition.table.c.id ) ),
  783. sample_form=relation( FormDefinition,
  784. primaryjoin=( RequestType.table.c.sample_form_id == FormDefinition.table.c.id ) ),
  785. ) )
  786. assign_mapper( context, RequestTypePermissions, RequestTypePermissions.table,
  787. properties=dict(
  788. request_type=relation( RequestType, backref="actions" ),
  789. role=relation( Role, backref="request_type_actions" )
  790. )
  791. )
  792. assign_mapper( context, FormDefinition, FormDefinition.table,
  793. properties=dict( current=relation( FormDefinitionCurrent,
  794. primaryjoin=( FormDefinition.table.c.form_definition_current_id == FormDefinitionCurrent.table.c.id ) )
  795. ) )
  796. assign_mapper( context, FormDefinitionCurrent, FormDefinitionCurrent.table,
  797. properties=dict( forms=relation( FormDefinition, backref='form_definition_current',
  798. cascade="all, delete-orphan",
  799. primaryjoin=( FormDefinitionCurrent.table.c.id == FormDefinition.table.c.form_definition_current_id ) ),
  800. latest_form=relation( FormDefinition, post_update=True,
  801. primaryjoin=( FormDefinitionCurrent.table.c.latest_form_id == FormDefinition.table.c.id ) )
  802. ) )
  803. assign_mapper( context, SampleEvent, SampleEvent.table,
  804. properties=dict( state=relation( SampleState,
  805. primaryjoin=( SampleEvent.table.c.sample_state_id == SampleState.table.c.id ) ),
  806. ) )
  807. assign_mapper( context, SampleState, SampleState.table,
  808. properties=None )
  809. assign_mapper( context, SampleDataset, SampleDataset.table,
  810. properties=None )
  811. assign_mapper( context, UserAddress, UserAddress.table,
  812. properties=dict(
  813. user=relation( User,
  814. primaryjoin=( UserAddress.table.c.user_id == User.table.c.id ),
  815. backref='addresses',
  816. order_by=desc(UserAddress.table.c.update_time)),
  817. ) )
  818. assign_mapper( context, ValidationError, ValidationError.table )
  819. assign_mapper( context, HistoryDatasetAssociation, HistoryDatasetAssociation.table,
  820. properties=dict(
  821. dataset=relation(
  822. Dataset,
  823. primaryjoin=( Dataset.table.c.id == HistoryDatasetAssociation.table.c.dataset_id ), lazy=False ),
  824. # .history defined in History mapper
  825. copied_to_history_dataset_associations=relation(
  826. HistoryDatasetAssociation,
  827. primaryjoin=( HistoryDatasetAssociation.table.c.copied_from_history_dataset_association_id == HistoryDatasetAssociation.table.c.id ),
  828. backref=backref( "copied_from_history_dataset_association", primaryjoin=( HistoryDatasetAssociation.table.c.copied_from_history_dataset_association_id == HistoryDatasetAssociation.table.c.id ), remote_side=[HistoryDatasetAssociation.table.c.id], uselist=False ) ),
  829. copied_to_library_dataset_dataset_associations=relation(
  830. LibraryDatasetDatasetAssociation,
  831. primaryjoin=( HistoryDatasetAssociation.table.c.copied_from_library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ),
  832. backref=backref( "copied_from_history_dataset_association", primaryjoin=( HistoryDatasetAssociation.table.c.copied_from_library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ), remote_side=[LibraryDatasetDatasetAssociation.table.c.id], uselist=False ) ),
  833. implicitly_converted_datasets=relation(
  834. ImplicitlyConvertedDatasetAssociation,
  835. primaryjoin=( ImplicitlyConvertedDatasetAssociation.table.c.hda_parent_id == HistoryDatasetAssociation.table.c.id ) ),
  836. children=relation(
  837. HistoryDatasetAssociation,
  838. primaryjoin=( HistoryDatasetAssociation.table.c.parent_id == HistoryDatasetAssociation.table.c.id ),
  839. backref=backref( "parent", primaryjoin=( HistoryDatasetAssociation.table.c.parent_id == HistoryDatasetAssociation.table.c.id ), remote_side=[HistoryDatasetAssociation.table.c.id], uselist=False ) ),
  840. visible_children=relation(
  841. HistoryDatasetAssociation,
  842. primaryjoin=( ( HistoryDatasetAssociation.table.c.parent_id == HistoryDatasetAssociation.table.c.id ) & ( HistoryDatasetAssociation.table.c.visible == True ) ) ),
  843. tags=relation( HistoryDatasetAssociationTagAssociation, order_by=HistoryDatasetAssociationTagAssociation.table.c.id, backref='history_tag_associations' ),
  844. annotations=relation( HistoryDatasetAssociationAnnotationAssociation, order_by=HistoryDatasetAssociationAnnotationAssociation.table.c.id, backref="hdas" ),
  845. ratings=relation( HistoryDatasetAssociationRatingAssociation, order_by=HistoryDatasetAssociationRatingAssociation.table.c.id, backref="hdas" ) )
  846. )
  847. assign_mapper( context, Dataset, Dataset.table,
  848. properties=dict(
  849. history_associations=relation(
  850. HistoryDatasetAssociation,
  851. primaryjoin=( Dataset.table.c.id == HistoryDatasetAssociation.table.c.dataset_id ) ),
  852. active_history_associations=relation(
  853. HistoryDatasetAssociation,
  854. primaryjoin=( ( Dataset.table.c.id == HistoryDatasetAssociation.table.c.dataset_id ) & ( HistoryDatasetAssociation.table.c.deleted == False ) ) ),
  855. library_associations=relation(
  856. LibraryDatasetDatasetAssociation,
  857. primaryjoin=( Dataset.table.c.id == LibraryDatasetDatasetAssociation.table.c.dataset_id ) ),
  858. active_library_associations=relation(
  859. LibraryDatasetDatasetAssociation,
  860. primaryjoin=( ( Dataset.table.c.id == LibraryDatasetDatasetAssociation.table.c.dataset_id ) & ( LibraryDatasetDatasetAssociation.table.c.deleted == False ) ) ),
  861. tags=relation(DatasetTagAssociation, order_by=DatasetTagAssociation.table.c.id, backref='datasets')
  862. ) )
  863. assign_mapper( context, HistoryDatasetAssociationDisplayAtAuthorization, HistoryDatasetAssociationDisplayAtAuthorization.table,
  864. properties=dict( history_dataset_association = relation( HistoryDatasetAssociation ),
  865. user = relation( User ) ) )
  866. assign_mapper( context, ImplicitlyConvertedDatasetAssociation, ImplicitlyConvertedDatasetAssociation.table,
  867. properties=dict( parent=relation(
  868. HistoryDatasetAssociation,
  869. primaryjoin=( ImplicitlyConvertedDatasetAssociation.table.c.hda_parent_id == HistoryDatasetAssociation.table.c.id ) ),
  870. dataset=relation(
  871. HistoryDatasetAssociation,
  872. primaryjoin=( ImplicitlyConvertedDatasetAssociation.table.c.hda_id == HistoryDatasetAssociation.table.c.id ) ) ) )
  873. assign_mapper( context, History, History.table,
  874. properties=dict( galaxy_sessions=relation( GalaxySessionToHistoryAssociation ),
  875. datasets=relation( HistoryDatasetAssociation, backref="history", order_by=asc(HistoryDatasetAssociation.table.c.hid) ),
  876. active_datasets=relation( HistoryDatasetAssociation, primaryjoin=( ( HistoryDatasetAssociation.table.c.history_id == History.table.c.id ) & ( not_( HistoryDatasetAssociation.table.c.deleted ) ) ), order_by=asc( HistoryDatasetAssociation.table.c.hid ), viewonly=True ),
  877. tags=relation( HistoryTagAssociation, order_by=HistoryTagAssociation.table.c.id, backref="histories" ),
  878. annotations=relation( HistoryAnnotationAssociation, order_by=HistoryAnnotationAssociation.table.c.id, backref="histories" ),
  879. ratings=relation( HistoryRatingAssociation, order_by=HistoryRatingAssociation.table.c.id, backref="histories" ) )
  880. )
  881. # Set up proxy so that
  882. # History.users_shared_with
  883. # returns a list of users that history is shared with.
  884. History.users_shared_with_dot_users = association_proxy( 'users_shared_with', 'user' )
  885. assign_mapper( context, HistoryUserShareAssociation, HistoryUserShareAssociation.table,
  886. properties=dict( user=relation( User, backref='histories_shared_by_others' ),
  887. history=relation( History, backref='users_shared_with' )
  888. ) )
  889. assign_mapper( context, User, User.table,
  890. properties=dict( histories=relation( History, backref="user",
  891. order_by=desc(History.table.c.update_time) ),
  892. active_histories=relation( History, primaryjoin=( ( History.table.c.user_id == User.table.c.id ) & ( not_( History.table.c.deleted ) ) ), order_by=desc( History.table.c.update_time ) ),
  893. galaxy_sessions=relation( GalaxySession, order_by=desc( GalaxySession.table.c.update_time ) ),
  894. stored_workflow_menu_entries=relation( StoredWorkflowMenuEntry, backref="user",
  895. cascade="all, delete-orphan",
  896. collection_class=ordering_list( 'order_index' ) ),
  897. _preferences=relation( UserPreference, backref="user", collection_class=attribute_mapped_collection('name')),
  898. # addresses=relation( UserAddress,
  899. # primaryjoin=( User.table.c.id == UserAddress.table.c.user_id ) )
  900. values=relation( FormValues,
  901. primaryjoin=( User.table.c.form_values_id == FormValues.table.c.id ) ),
  902. api_keys=relation( APIKeys, backref="user", order_by=desc( APIKeys.table.c.create_time ) ),
  903. ) )
  904. # Set up proxy so that this syntax is possible:
  905. # <user_obj>.preferences[pref_name] = pref_value
  906. User.preferences = association_proxy('_preferences', 'value', creator=UserPreference)
  907. assign_mapper( context, Group, Group.table,
  908. properties=dict( users=relation( UserGroupAssociation ) ) )
  909. assign_mapper( context, UserGroupAssociation, UserGroupAssociation.table,
  910. properties=dict( user=relation( User, backref = "groups" ),
  911. group=relation( Group, backref = "members" ) ) )
  912. assign_mapper( context, DefaultUserPermissions, DefaultUserPermissions.table,
  913. properties=dict( user=relation( User, backref = "default_permissions" ),
  914. role=relation( Role ) ) )
  915. assign_mapper( context, DefaultHistoryPermissions, DefaultHistoryPermissions.table,
  916. properties=dict( history=relation( History, backref = "default_permissions" ),
  917. role=relation( Role ) ) )
  918. assign_mapper( context, Role, Role.table,
  919. properties=dict(
  920. users=relation( UserRoleAssociation ),
  921. groups=relation( GroupRoleAssociation )
  922. )
  923. )
  924. assign_mapper( context, UserRoleAssociation, UserRoleAssociation.table,
  925. properties=dict(
  926. user=relation( User, backref="roles" ),
  927. non_private_roles=relation( User,
  928. backref="non_private_roles",
  929. primaryjoin=( ( User.table.c.id == UserRoleAssociation.table.c.user_id ) & ( UserRoleAssociation.table.c.role_id == Role.table.c.id ) & not_( Role.table.c.name == User.table.c.email ) ) ),
  930. role=relation( Role )
  931. )
  932. )
  933. assign_mapper( context, GroupRoleAssociation, GroupRoleAssociation.table,
  934. properties=dict(
  935. group=relation( Group, backref="roles" ),
  936. role=relation( Role )
  937. )
  938. )
  939. assign_mapper( context, DatasetPermissions, DatasetPermissions.table,
  940. properties=dict(
  941. dataset=relation( Dataset, backref="actions" ),
  942. role=relation( Role, backref="dataset_actions" )
  943. )
  944. )
  945. assign_mapper( context, LibraryPermissions, LibraryPermissions.table,
  946. properties=dict(
  947. library=relation( Library, backref="actions" ),
  948. role=relation( Role, backref="library_actions" )
  949. )
  950. )
  951. assign_mapper( context, LibraryFolderPermissions, LibraryFolderPermissions.table,
  952. properties=dict(
  953. folder=relation( LibraryFolder, backref="actions" ),
  954. role=relation( Role, backref="library_folder_actions" )
  955. )
  956. )
  957. assign_mapper( context, LibraryDatasetPermissions, LibraryDatasetPermissions.table,
  958. properties=dict(
  959. library_dataset=relation( LibraryDataset, backref="actions" ),
  960. role=relation( Role, backref="library_dataset_actions" )
  961. )
  962. )
  963. assign_mapper( context, LibraryDatasetDatasetAssociationPermissions, LibraryDatasetDatasetAssociationPermissions.table,
  964. properties=dict(
  965. library_dataset_dataset_association = relation( LibraryDatasetDatasetAssociation, backref="actions" ),
  966. role=relation( Role, backref="library_dataset_dataset_actions" )
  967. )
  968. )
  969. assign_mapper( context, Library, Library.table,
  970. properties=dict(
  971. root_folder=relation( LibraryFolder, backref=backref( "library_root" ) )
  972. )
  973. )
  974. assign_mapper( context, LibraryInfoAssociation, LibraryInfoAssociation.table,
  975. properties=dict( library=relation( Library,
  976. primaryjoin=( ( LibraryInfoAssociation.table.c.library_id == Library.table.c.id ) & ( not_( LibraryInfoAssociation.table.c.deleted ) ) ), backref="info_association" ),
  977. template=relation( FormDefinition,
  978. primaryjoin=( LibraryInfoAssociation.table.c.form_definition_id == FormDefinition.table.c.id ) ),
  979. info=relation( FormValues,
  980. primaryjoin=( LibraryInfoAssociation.table.c.form_values_id == FormValues.table.c.id ) )
  981. ) )
  982. assign_mapper( context, LibraryFolder, LibraryFolder.table,
  983. properties=dict(
  984. folders=relation(
  985. LibraryFolder,
  986. primaryjoin=( LibraryFolder.table.c.parent_id == LibraryFolder.table.c.id ),
  987. order_by=asc( LibraryFolder.table.c.name ),
  988. backref=backref( "parent", primaryjoin=( LibraryFolder.table.c.parent_id == LibraryFolder.table.c.id ), remote_side=[LibraryFolder.table.c.id] ) ),
  989. active_folders=relation( LibraryFolder,
  990. primaryjoin=( ( LibraryFolder.table.c.parent_id == LibraryFolder.table.c.id ) & ( not_( LibraryFolder.table.c.deleted ) ) ),
  991. order_by=asc( LibraryFolder.table.c.name ),
  992. lazy=True, #"""sqlalchemy.exceptions.ArgumentError: Error creating eager relationship 'active_folders' on parent class '<class 'galaxy.model.LibraryFolder'>' to child class '<class 'galaxy.model.LibraryFolder'>': Cant use eager loading on a self referential relationship."""
  993. viewonly=True ),
  994. datasets=relation( LibraryDataset,
  995. primaryjoin=( ( LibraryDataset.table.c.folder_id == LibraryFolder.table.c.id ) ),
  996. order_by=asc( LibraryDataset.table.c._name ),
  997. lazy=False,
  998. viewonly=True )
  999. ) )
  1000. assign_mapper( context, LibraryFolderInfoAssociation, LibraryFolderInfoAssociation.table,
  1001. properties=dict( folder=relation( LibraryFolder,
  1002. primaryjoin=( ( LibraryFolderInfoAssociation.table.c.library_folder_id == LibraryFolder.table.c.id ) & ( not_( LibraryFolderInfoAssociation.table.c.deleted ) ) ), backref="info_association" ),
  1003. template=relation( FormDefinition,
  1004. primaryjoin=( LibraryFolderInfoAssociation.table.c.form_definition_id == FormDefinition.table.c.id ) ),
  1005. info=relation( FormValues,
  1006. primaryjoin=( LibraryFolderInfoAssociation.table.c.form_values_id == FormValues.table.c.id ) )
  1007. ) )
  1008. assign_mapper( context, LibraryDataset, LibraryDataset.table,
  1009. properties=dict(
  1010. folder=relation( LibraryFolder ),
  1011. library_dataset_dataset_association=relation( LibraryDatasetDatasetAssociation, primaryjoin=( LibraryDataset.table.c.library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ) ),
  1012. expired_datasets = relation( LibraryDatasetDatasetAssociation, foreign_keys=[LibraryDataset.table.c.id,LibraryDataset.table.c.library_dataset_dataset_association_id ], primaryjoin=( ( LibraryDataset.table.c.id == LibraryDatasetDatasetAssociation.table.c.library_dataset_id ) & ( not_( LibraryDataset.table.c.library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ) ) ), viewonly=True, uselist=True )
  1013. ) )
  1014. assign_mapper( context, LibraryDatasetDatasetAssociation, LibraryDatasetDatasetAssociation.table,
  1015. properties=dict(
  1016. dataset=relation( Dataset ),
  1017. library_dataset = relation( LibraryDataset,
  1018. primaryjoin=( LibraryDatasetDatasetAssociation.table.c.library_dataset_id == LibraryDataset.table.c.id ) ),
  1019. user=relation( User.mapper ),
  1020. copied_to_library_dataset_dataset_associations=relation(
  1021. LibraryDatasetDatasetAssociation,
  1022. primaryjoin=( LibraryDatasetDatasetAssociation.table.c.copied_from_library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ),
  1023. backref=backref( "copied_from_library_dataset_dataset_association", primaryjoin=( LibraryDatasetDatasetAssociation.table.c.copied_from_library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ), remote_side=[LibraryDatasetDatasetAssociation.table.c.id] ) ),
  1024. copied_to_history_dataset_associations=relation(
  1025. HistoryDatasetAssociation,
  1026. primaryjoin=( HistoryDatasetAssociation.table.c.copied_from_library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ),
  1027. backref=backref( "copied_from_library_dataset_dataset_association", primaryjoin=( HistoryDatasetAssociation.table.c.copied_from_library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ), remote_side=[LibraryDatasetDatasetAssociation.table.c.id], uselist=False ) ),
  1028. children=relation(
  1029. LibraryDatasetDatasetAssociation,
  1030. primaryjoin=( LibraryDatasetDatasetAssociation.table.c.parent_id == LibraryDatasetDatasetAssociation.table.c.id ),
  1031. backref=backref( "parent", primaryjoin=( LibraryDatasetDatasetAssociation.table.c.parent_id == LibraryDatasetDatasetAssociation.table.c.id ), remote_side=[LibraryDatasetDatasetAssociation.table.c.id] ) ),
  1032. visible_children=relation(
  1033. LibraryDatasetDatasetAssociation,
  1034. primaryjoin=( ( LibraryDatasetDatasetAssociation.table.c.parent_id == LibraryDatasetDatasetAssociation.table.c.id ) & ( LibraryDatasetDatasetAssociation.table.c.visible == True ) ) )
  1035. ) )
  1036. assign_mapper( context, LibraryDatasetDatasetInfoAssociation, LibraryDatasetDatasetInfoAssociation.table,
  1037. properties=dict( library_dataset_dataset_association=relation( LibraryDatasetDatasetAssociation,
  1038. primaryjoin=( ( LibraryDatasetDatasetInfoAssociation.table.c.library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ) & ( not_( LibraryDatasetDatasetInfoAssociation.table.c.deleted ) ) ), backref="info_association" ),
  1039. template=relation( FormDefinition,
  1040. primaryjoin=( LibraryDatasetDatasetInfoAssociation.table.c.form_definition_id == FormDefinition.table.c.id ) ),
  1041. info=relation( FormValues,
  1042. primaryjoin=( LibraryDatasetDatasetInfoAssociation.table.c.form_values_id == FormValues.table.c.id ) )
  1043. ) )
  1044. assign_mapper( context, JobToInputDatasetAssociation, JobToInputDatasetAssociation.table,
  1045. properties=dict( job=relation( Job ), dataset=relation( HistoryDatasetAssociation, lazy=False ) ) )
  1046. assign_mapper( context, JobToOutputDatasetAssociation, JobToOutputDatasetAssociation.table,
  1047. properties=dict( job=relation( Job ), dataset=relation( HistoryDatasetAssociation, lazy=False ) ) )
  1048. assign_mapper( context, JobToOutputLibraryDatasetAssociation, JobToOutputLibraryDatasetAssociation.table,
  1049. properties=dict( job=relation( Job ), dataset=relation( LibraryDatasetDatasetAssociation, lazy=False ) ) )
  1050. assign_mapper( context, JobParameter, JobParameter.table )
  1051. assign_mapper( context, JobExternalOutputMetadata, JobExternalOutputMetadata.table,
  1052. properties=dict( job = relation( Job ),
  1053. history_dataset_association = relation( HistoryDatasetAssociation, lazy = False ),
  1054. library_dataset_dataset_association = relation( LibraryDatasetDatasetAssociation, lazy = False ) ) )
  1055. assign_mapper( context, PostJobAction, PostJobAction.table,
  1056. properties=dict(workflow_step = relation( WorkflowStep, backref='post_job_actions', primaryjoin=(WorkflowStep.table.c.id == PostJobAction.table.c.workflow_step_id))))
  1057. assign_mapper( context, PostJobActionAssociation, PostJobActionAssociation.table,
  1058. properties=dict( job = relation( Job ),
  1059. post_job_action = relation( PostJobAction) ) )
  1060. assign_mapper( context, Job, Job.table,
  1061. properties=dict( user=relation( User.mapper ),
  1062. galaxy_session=relation( GalaxySession ),
  1063. history=relation( History ),
  1064. library_folder=relation( LibraryFolder ),
  1065. parameters=relation( JobParameter, lazy=False ),
  1066. input_datasets=relation( JobToInputDatasetAssociation, lazy=False ),
  1067. output_datasets=relation( JobToOutputDatasetAssociation, lazy=False ),
  1068. post_job_actions=relation( PostJobActionAssociation, lazy=False ),
  1069. output_library_datasets=relation( JobToOutputLibraryDatasetAssociation, lazy=False ),
  1070. external_output_metadata = relation( JobExternalOutputMetadata, lazy = False ) ) )
  1071. assign_mapper( context, Event, Event.table,
  1072. properties=dict( history=relation( History ),
  1073. galaxy_session=relation( GalaxySession ),
  1074. user=relation( User.mapper ) ) )
  1075. assign_mapper( context, GalaxySession, GalaxySession.table,
  1076. properties=dict( histories=relation( GalaxySessionToHistoryAssociation ),
  1077. current_history=relation( History ),
  1078. user=relation( User.mapper ) ) )
  1079. assign_mapper( context, GalaxySessionToHistoryAssociation, GalaxySessionToHistoryAssociation.table,
  1080. properties=dict( galaxy_session=relation( GalaxySession ),
  1081. history=relation( History ) ) )
  1082. HistoryDatasetAssociation.mapper.add_property( "creating_job_associations", relation( JobToOutputDatasetAssociation ) )
  1083. assign_mapper( context, Workflow, Workflow.table,
  1084. properties=dict( steps=relation( WorkflowStep, backref='workflow',
  1085. order_by=asc(WorkflowStep.table.c.order_index),
  1086. cascade="all, delete-orphan",
  1087. lazy=False )
  1088. ) )
  1089. assign_mapper( context, WorkflowStep, WorkflowStep.table,
  1090. properties=dict(
  1091. tags=relation(WorkflowStepTagAssociation, order_by=WorkflowStepTagAssociation.table.c.id, backref="workflow_steps"),
  1092. annotations=relation( WorkflowStepAnnotationAssociation, order_by=WorkflowStepAnnotationAssociation.table.c.id, backref="workflow_steps" ) )
  1093. )
  1094. assign_mapper( context, WorkflowStepConnection, WorkflowStepConnection.table,
  1095. properties=dict( input_step=relation( WorkflowStep, backref="input_connections", cascade="all",
  1096. primaryjoin=( WorkflowStepConnection.table.c.input_step_id == WorkflowStep.table.c.id ) ),
  1097. output_step=relation( WorkflowStep, backref="output_connections", cascade="all",
  1098. primaryjoin=( WorkflowStepConnection.table.c.output_step_id == WorkflowStep.table.c.id ) ) ) )
  1099. assign_mapper( context, StoredWorkflow, StoredWorkflow.table,
  1100. properties=dict( user=relation( User,
  1101. primaryjoin=( User.table.c.id == StoredWorkflow.table.c.user_id ),
  1102. backref='stored_workflows' ),
  1103. workflows=relation( Workflow, backref='stored_workflow',
  1104. cascade="all, delete-orphan",
  1105. primaryjoin=( StoredWorkflow.table.c.id == Workflow.table.c.stored_workflow_id ) ),
  1106. latest_workflow=relation( Workflow, post_update=True,
  1107. primaryjoin=( StoredWorkflow.table.c.latest_workflow_id == Workflow.table.c.id ),
  1108. lazy=False ),
  1109. tags=relation( StoredWorkflowTagAssociation, order_by=StoredWorkflowTagAssociation.table.c.id, backref="stored_workflows" ),
  1110. annotations=relation( StoredWorkflowAnnotationAssociation, order_by=StoredWorkflowAnnotationAssociation.table.c.id, backref="stored_workflows" ),
  1111. ratings=relation( StoredWorkflowRatingAssociation, order_by=StoredWorkflowRatingAssociation.table.c.id, backref="stored_workflows" ) )
  1112. )
  1113. # Set up proxy so that
  1114. # StoredWorkflow.users_shared_with
  1115. # returns a list of users that workflow is shared with.
  1116. StoredWorkflow.users_shared_with_dot_users = association_proxy( 'users_shared_with', 'user' )
  1117. assign_mapper( context, StoredWorkflowUserShareAssociation, StoredWorkflowUserShareAssociation.table,
  1118. properties=dict( user=relation( User, backref='workflows_shared_by_others' ),
  1119. stored_workflow=relation( StoredWorkflow, backref='users_shared_with' )
  1120. ) )
  1121. assign_mapper( context, StoredWorkflowMenuEntry, StoredWorkflowMenuEntry.table,
  1122. properties=dict( stored_workflow=relation( StoredWorkflow ) ) )
  1123. assign_mapper( context, WorkflowInvocation, WorkflowInvocation.table,
  1124. properties=dict(
  1125. steps=relation( WorkflowInvocationStep, backref='workflow_invocation', lazy=False ),
  1126. workflow=relation( Workflow ) ) )
  1127. assign_mapper( context, WorkflowInvocationStep, WorkflowInvocationStep.table,
  1128. properties=dict(
  1129. workflow_step = relation( WorkflowStep ),
  1130. job = relation( Job, backref=backref( 'workflow_invocation_step', uselist=False ) ) ) )
  1131. assign_mapper( context, MetadataFile, MetadataFile.table,
  1132. properties=dict( history_dataset=relation( HistoryDatasetAssociation ), library_dataset=relation( LibraryDatasetDatasetAssociation ) ) )
  1133. assign_mapper( context, PageRevision, PageRevision.table )
  1134. assign_mapper( context, Page, Page.table,
  1135. properties=dict( user=relation( User ),
  1136. revisions=relation( PageRevision, backref='page',
  1137. cascade="all, delete-orphan",
  1138. primaryjoin=( Page.table.c.id == PageRevision.table.c.page_id ) ),
  1139. latest_revision=relation( PageRevision, post_update=True,
  1140. primaryjoin=( Page.table.c.latest_revision_id == PageRevision.table.c.id ),
  1141. lazy=False ),
  1142. tags=relation(PageTagAssociation, order_by=PageTagAssociation.table.c.id, backref="pages"),
  1143. annotations=relation( PageAnnotationAssociation, order_by=PageAnnotationAssociation.table.c.id, backref="pages" ),
  1144. ratings=relation( PageRatingAssociation, order_by=PageRatingAssociation.table.c.id, backref="pages" )
  1145. ) )
  1146. # Set up proxy so that
  1147. # Page.users_shared_with
  1148. # returns a list of users that page is shared with.
  1149. Page.users_shared_with_dot_users = association_proxy( 'users_shared_with', 'user' )
  1150. assign_mapper( context, PageUserShareAssociation, PageUserShareAssociation.table,
  1151. properties=dict( user=relation( User, backref='pages_shared_by_others' ),
  1152. page=relation( Page, backref='users_shared_with' )
  1153. ) )
  1154. assign_mapper( context, VisualizationRevision, VisualizationRevision.table )
  1155. assign_mapper( context, Visualization, Visualization.table,
  1156. properties=dict( user=relation( User ),
  1157. revisions=relation( VisualizationRevision, backref='visualization',
  1158. cascade="all, delete-orphan",
  1159. primaryjoin=( Visualization.table.c.id == VisualizationRevision.table.c.visualization_id ) ),
  1160. latest_revision=relation( VisualizationRevision, post_update=True,
  1161. primaryjoin=( Visualization.table.c.latest_revision_id == VisualizationRevision.table.c.id ),
  1162. lazy=False ),
  1163. tags=relation( VisualizationTagAssociation, order_by=VisualizationTagAssociation.table.c.id, backref="visualizations" ),
  1164. annotations=relation( VisualizationAnnotationAssociation, order_by=VisualizationAnnotationAssociation.table.c.id, backref="visualizations" ),
  1165. ratings=relation( VisualizationRatingAssociation, order_by=VisualizationRatingAssociation.table.c.id, backref="visualizations" )
  1166. ) )
  1167. # Set up proxy so that
  1168. # Visualization.users_shared_with
  1169. # returns a list of users that visualization is shared with.
  1170. Visualization.users_shared_with_dot_users = association_proxy( 'users_shared_with', 'user' )
  1171. assign_mapper( context, VisualizationUserShareAssociation, VisualizationUserShareAssociation.table,
  1172. properties=dict( user=relation( User, backref='visualizations_shared_by_others' ),
  1173. visualization=relation( Visualization, backref='users_shared_with' )
  1174. ) )
  1175. # Tag tables.
  1176. assign_mapper( context, Tag, Tag.table,
  1177. properties=dict( children=relation(Tag, backref=backref( 'parent', remote_side=[Tag.table.c.id] ) )
  1178. ) )
  1179. assign_mapper( context, HistoryTagAssociation, HistoryTagAssociation.table,
  1180. properties=dict( tag=relation(Tag, backref="tagged_histories"), user=relation( User ) )
  1181. )
  1182. assign_mapper( context, DatasetTagAssociation, DatasetTagAssociation.table,
  1183. properties=dict( tag=relation(Tag, backref="tagged_datasets"), user=relation( User ) )
  1184. )
  1185. assign_mapper( context, HistoryDatasetAssociationTagAssociation, HistoryDatasetAssociationTagAssociation.table,
  1186. properties=dict( tag=relation(Tag, backref="tagged_history_dataset_associations"), user=relation( User ) )
  1187. )
  1188. assign_mapper( context, PageTagAssociation, PageTagAssociation.table,
  1189. properties=dict( tag=relation(Tag, backref="tagged_pages"), user=relation( User ) )
  1190. )
  1191. assign_mapper( context, StoredWorkflowTagAssociation, StoredWorkflowTagAssociation.table,
  1192. properties=dict( tag=relation(Tag, backref="tagged_workflows"), user=relation( User ) )
  1193. )
  1194. assign_mapper( context, WorkflowStepTagAssociation, WorkflowStepTagAssociation.table,
  1195. properties=dict( tag=relation(Tag, backref="tagged_workflow_steps"), user=relation( User ) )
  1196. )
  1197. assign_mapper( context, VisualizationTagAssociation, VisualizationTagAssociation.table,
  1198. properties=dict( tag=relation(Tag, backref="tagged_visualizations"), user=relation( User ) )
  1199. )
  1200. # Annotation tables.
  1201. assign_mapper( context, HistoryAnnotationAssociation, HistoryAnnotationAssociation.table,
  1202. properties=dict( history=relation( History ), user=relation( User ) )
  1203. )
  1204. assign_mapper( context, HistoryDatasetAssociationAnnotationAssociation, HistoryDatasetAssociationAnnotationAssociation.table,
  1205. properties=dict( hda=relation( HistoryDatasetAssociation ), user=relation( User ) )
  1206. )
  1207. assign_mapper( context, StoredWorkflowAnnotationAssociation, StoredWorkflowAnnotationAssociation.table,
  1208. properties=dict( stored_workflow=relation( StoredWorkflow ), user=relation( User ) )
  1209. )
  1210. assign_mapper( context, WorkflowStepAnnotationAssociation, WorkflowStepAnnotationAssociation.table,
  1211. properties=dict( workflow_step=relation( WorkflowStep ), user=relation( User ) )
  1212. )
  1213. assign_mapper( context, PageAnnotationAssociation, PageAnnotationAssociation.table,
  1214. properties=dict( page=relation( Page ), user=relation( User ) )
  1215. )
  1216. assign_mapper( context, VisualizationAnnotationAssociation, VisualizationAnnotationAssociation.table,
  1217. properties=dict( visualization=relation( Visualization ), user=relation( User ) )
  1218. )
  1219. # Rating tables.
  1220. assign_mapper( context, HistoryRatingAssociation, HistoryRatingAssociation.table,
  1221. properties=dict( history=relation( History ), user=relation( User ) )
  1222. )
  1223. assign_mapper( context, HistoryDatasetAssociationRatingAssociation, HistoryDatasetAssociationRatingAssociation.table,
  1224. properties=dict( hda=relation( HistoryDatasetAssociation ), user=relation( User ) )
  1225. )
  1226. assign_mapper( context, StoredWorkflowRatingAssociation, StoredWorkflowRatingAssociation.table,
  1227. properties=dict( stored_workflow=relation( StoredWorkflow ), user=relation( User ) )
  1228. )
  1229. assign_mapper( context, PageRatingAssociation, PageRatingAssociation.table,
  1230. properties=dict( page=relation( Page ), user=relation( User ) )
  1231. )
  1232. assign_mapper( context, VisualizationRatingAssociation, VisualizationRatingAssociation.table,
  1233. properties=dict( visualization=relation( Visualization ), user=relation( User ) )
  1234. )
  1235. # User tables.
  1236. assign_mapper( context, UserPreference, UserPreference.table,
  1237. properties = {}
  1238. )
  1239. assign_mapper( context, UserAction, UserAction.table,
  1240. properties = dict( user=relation( User.mapper ) )
  1241. )
  1242. assign_mapper( context, APIKeys, APIKeys.table,
  1243. properties = {} )
  1244. # Helper methods.
  1245. def db_next_hid( self ):
  1246. """
  1247. Override __next_hid to generate from the database in a concurrency
  1248. safe way.
  1249. """
  1250. conn = object_session( self ).connection()
  1251. table = self.table
  1252. trans = conn.begin()
  1253. try:
  1254. next_hid = select( [table.c.hid_counter], table.c.id == self.id, for_update=True ).scalar()
  1255. table.update( table.c.id == self.id ).execute( hid_counter = ( next_hid + 1 ) )
  1256. trans.commit()
  1257. return next_hid
  1258. except:
  1259. trans.rollback()
  1260. raise
  1261. History._next_hid = db_next_hid
  1262. def guess_dialect_for_url( url ):
  1263. return (url.split(':', 1))[0]
  1264. def load_egg_for_url( url ):
  1265. # Load the appropriate db module
  1266. dialect = guess_dialect_for_url( url )
  1267. try:
  1268. egg = dialect_to_egg[dialect]
  1269. try:
  1270. pkg_resources.require( egg )
  1271. log.debug( "%s egg successfully loaded for %s dialect" % ( egg, dialect ) )
  1272. except:
  1273. # If the module's in the path elsewhere (i.e. non-egg), it'll still load.
  1274. log.warning( "%s egg not found, but an attempt will be made to use %s anyway" % ( egg, dialect ) )
  1275. except KeyError:
  1276. # Let this go, it could possibly work with db's we don't support
  1277. log.error( "database_connection contains an unknown SQLAlchemy database dialect: %s" % dialect )
  1278. def init( file_path, url, engine_options={}, create_tables=False ):
  1279. """Connect mappings to the database"""
  1280. # Connect dataset to the file path
  1281. Dataset.file_path = file_path
  1282. # Load the appropriate db module
  1283. load_egg_for_url( url )
  1284. # Create the database engine
  1285. engine = create_engine( url, **engine_options )
  1286. # Connect the metadata to the database.
  1287. metadata.bind = engine
  1288. # Clear any existing contextual sessions and reconfigure
  1289. Session.remove()
  1290. Session.configure( bind=engine )
  1291. # Create tables if needed
  1292. if create_tables:
  1293. metadata.create_all()
  1294. # metadata.engine.commit()
  1295. # Pack everything into a bunch
  1296. result = Bunch( **globals() )
  1297. result.engine = engine
  1298. # model.flush() has been removed.
  1299. result.session = Session
  1300. # For backward compatibility with "model.context.current"
  1301. result.context = Session
  1302. result.create_tables = create_tables
  1303. #load local galaxy security policy
  1304. result.security_agent = GalaxyRBACAgent( result )
  1305. return result
  1306. def get_suite():
  1307. """Get unittest suite for this module"""
  1308. import unittest, mapping_tests
  1309. return unittest.makeSuite( mapping_tests.MappingTests )