tripal_chado.install 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <?php
  2. function tripal_chado_install() {
  3. // // The foreign key specification doesn't really add one to the
  4. // // Drupal schema, it is just used internally, but we want one.
  5. // db_query('
  6. // ALTER TABLE {tripal_custom_tables}
  7. // ADD CONSTRAINT tripal_custom_tables_fk1
  8. // FOREIGN KEY (mview_id) REFERENCES {tripal_mviews} (mview_id)
  9. // ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
  10. // ');
  11. }
  12. /**
  13. * Implementation of hook_uninstall().
  14. *
  15. * @ingroup tripal
  16. */
  17. function tripal_chado_uninstall() {
  18. // // Drop the foreign key between tripal_custom_tables and tripal_mviews
  19. // // so that Drupal can then drop the tables
  20. // db_query('
  21. // ALTER TABLE {tripal_custom_tables}
  22. // DROP CONSTRAINT tripal_custom_tables_fk1 CASCADE
  23. // ');
  24. }
  25. /**
  26. * Table definition for the tripal_cv_obo table
  27. * @param $schema
  28. */
  29. function tripal_chado_tripal_cv_obo_schema() {
  30. return array(
  31. 'fields' => array(
  32. 'obo_id' => array(
  33. 'type' => 'serial',
  34. 'unsigned' => TRUE,
  35. 'not null' => TRUE
  36. ),
  37. 'name' => array(
  38. 'type' => 'varchar',
  39. 'length' => 255
  40. ),
  41. 'path' => array(
  42. 'type' => 'varchar',
  43. 'length' => 1024
  44. ),
  45. ),
  46. 'indexes' => array(
  47. 'tripal_cv_obo_idx1' => array('obo_id'),
  48. ),
  49. 'primary key' => array('obo_id'),
  50. );
  51. }
  52. /**
  53. * * Table definition for the tripal_cv_defaults table
  54. * @param unknown $schema
  55. */
  56. function tripal_chado_tripal_cv_defaults_schema() {
  57. return array(
  58. 'fields' => array(
  59. 'cv_default_id' => array(
  60. 'type' => 'serial',
  61. 'unsigned' => TRUE,
  62. 'not null' => TRUE
  63. ),
  64. 'table_name' => array(
  65. 'type' => 'varchar',
  66. 'length' => 128,
  67. 'not null' => TRUE,
  68. ),
  69. 'field_name' => array(
  70. 'type' => 'varchar',
  71. 'length' => 128,
  72. 'not null' => TRUE,
  73. ),
  74. 'cv_id' => array(
  75. 'type' => 'int',
  76. 'not null' => TRUE,
  77. )
  78. ),
  79. 'indexes' => array(
  80. 'tripal_cv_defaults_idx1' => array('table_name', 'field_name'),
  81. ),
  82. 'unique keys' => array(
  83. 'tripal_cv_defaults_unq1' => array('table_name', 'field_name', 'cv_id'),
  84. ),
  85. 'primary key' => array('cv_default_id')
  86. );
  87. }
  88. /**
  89. * Implements hook_schema().
  90. */
  91. function tripal_chado_schema() {
  92. // Links TripalEntity entities to the chado record.
  93. $schema['chado_entity'] = tripal_chado_chado_entity_schema();
  94. $schema['tripal_mviews'] = tripal_chado_tripal_mviews_schema();
  95. $schema['tripal_custom_tables'] = tripal_chado_tripal_custom_tables_schema();
  96. $schema['tripal_cv_obo'] = tripal_chado_tripal_cv_obo_schema();
  97. $schema['tripal_cv_defaults'] = tripal_chado_tripal_cv_defaults_schema();
  98. $schema['tripal_pub_import'] = tripal_chado_tripal_pub_import_schema();
  99. // if this module is already installed and enabled, then we want to provide
  100. // the schemas for all of the custom tables. This will allow Views to
  101. // see the schemas. We check if the module is installed because during
  102. // installation we don't want to make these custom tables available as we don't
  103. // want them created in the Drupal database. The custom tables go in the
  104. // Chado database.
  105. if (db_table_exists('tripal_custom_tables')) {
  106. $sql = 'SELECT * FROM {tripal_custom_tables}';
  107. $results = db_query($sql);
  108. foreach ($results as $custom) {
  109. $schema[$custom->table_name] = unserialize($custom->schema);
  110. }
  111. }
  112. return $schema;
  113. }
  114. /**
  115. * @section
  116. * Schema Definitions.
  117. */
  118. /**
  119. * Implementation of hook_schema().
  120. *
  121. * @ingroup tripal_pub
  122. */
  123. function tripal_chado_tripal_pub_import_schema() {
  124. return array(
  125. 'fields' => array(
  126. 'pub_import_id' => array(
  127. 'type' => 'serial',
  128. 'not null' => TRUE
  129. ),
  130. 'name' => array(
  131. 'type' => 'varchar',
  132. 'length' => 255,
  133. 'not null' => TRUE
  134. ),
  135. 'criteria' => array(
  136. 'type' => 'text',
  137. 'size' => 'normal',
  138. 'not null' => TRUE,
  139. 'description' => 'Contains a serialized PHP array containing the search criteria'
  140. ),
  141. 'disabled' => array(
  142. 'type' => 'int',
  143. 'unsigned' => TRUE,
  144. 'not NULL' => TRUE,
  145. 'default' => 0
  146. ),
  147. 'do_contact' => array(
  148. 'type' => 'int',
  149. 'unsigned' => TRUE,
  150. 'not NULL' => TRUE,
  151. 'default' => 0
  152. ),
  153. ),
  154. 'primary key' => array('pub_import_id'),
  155. 'indexes' => array(
  156. 'name' => array('name')
  157. ),
  158. );
  159. }
  160. /**
  161. * Describes the Tripal Custom Tables (tripal_custom_tables) table
  162. * This keeps track of tables created by Tripal and stored in chado that may or may not
  163. * also be materialized views.
  164. *
  165. * @ingroup tripal
  166. */
  167. function tripal_chado_tripal_custom_tables_schema() {
  168. return array(
  169. 'fields' => array(
  170. 'table_id' => array(
  171. 'type' => 'serial',
  172. 'unsigned' => TRUE,
  173. 'not NULL' => TRUE
  174. ),
  175. 'table_name' => array(
  176. 'type' => 'varchar',
  177. 'length' => 255,
  178. 'not NULL' => TRUE
  179. ),
  180. 'schema' => array(
  181. 'type' => 'text',
  182. 'not NULL' => TRUE
  183. ),
  184. 'mview_id' => array(
  185. 'type' => 'int',
  186. 'not NULL' => FALSE
  187. )
  188. ),
  189. 'indexes' => array(
  190. 'table_id' => array('table_id'),
  191. ),
  192. 'primary key' => array('table_id'),
  193. 'foreign keys' => array(
  194. 'tripal_mviews' => array(
  195. 'table' => 'tripal_mviews',
  196. 'columns' => array(
  197. 'mview_id' => 'mview_id'
  198. ),
  199. ),
  200. ),
  201. );
  202. }
  203. /**
  204. * Describes the Tripal Materialized View (tripal_mviews) table
  205. * This table keeps track of all materialized views created by Tripal and stored in chado
  206. *
  207. * @ingroup tripal
  208. */
  209. function tripal_chado_tripal_mviews_schema() {
  210. return array(
  211. 'fields' => array(
  212. 'mview_id' => array(
  213. 'type' => 'serial',
  214. 'unsigned' => TRUE,
  215. 'not NULL' => TRUE
  216. ),
  217. 'name' => array(
  218. 'type' => 'varchar',
  219. 'length' => 255,
  220. 'not NULL' => TRUE
  221. ),
  222. 'modulename' => array(
  223. 'type' => 'varchar',
  224. 'length' => 50,
  225. 'not NULL' => TRUE,
  226. 'description' => 'The module name that provides the callback for this job'
  227. ),
  228. 'mv_table' => array(
  229. 'type' => 'varchar',
  230. 'length' => 128,
  231. 'not NULL' => FALSE
  232. ),
  233. 'mv_specs' => array(
  234. 'type' => 'text',
  235. 'size' => 'normal',
  236. 'not NULL' => FALSE
  237. ),
  238. 'mv_schema' => array(
  239. 'type' => 'text',
  240. 'size' => 'normal',
  241. 'not NULL' => FALSE
  242. ),
  243. 'indexed' => array(
  244. 'type' => 'text',
  245. 'size' => 'normal',
  246. 'not NULL' => FALSE
  247. ),
  248. 'query' => array(
  249. 'type' => 'text',
  250. 'size' => 'normal',
  251. 'not NULL' => TRUE
  252. ),
  253. 'special_index' => array(
  254. 'type' => 'text',
  255. 'size' => 'normal',
  256. 'not NULL' => FALSE
  257. ),
  258. 'last_update' => array(
  259. 'type' => 'int',
  260. 'not NULL' => FALSE,
  261. 'description' => 'UNIX integer time'
  262. ),
  263. 'status' => array(
  264. 'type' => 'text',
  265. 'size' => 'normal',
  266. 'not NULL' => FALSE
  267. ),
  268. 'comment' => array(
  269. 'type' => 'text',
  270. 'size' => 'normal',
  271. 'not NULL' => FALSE
  272. ),
  273. ),
  274. 'indexes' => array(
  275. 'mview_id' => array('mview_id')
  276. ),
  277. 'unique keys' => array(
  278. 'mv_table' => array('mv_table'),
  279. 'mv_name' => array('name'),
  280. ),
  281. 'primary key' => array('mview_id'),
  282. );
  283. }
  284. /**
  285. * Links Biological Data Entities to the chado "base" table the data is stored in.
  286. * This is where we would specify that a particular gene maps to the record in the
  287. * chado.feature table with a feature_id=2432;
  288. */
  289. function tripal_chado_chado_entity_schema() {
  290. $schema = array(
  291. 'description' => 'The linker table that associates an enitity from the public.tripal_entity table with a "base" record in Chado',
  292. 'fields' => array(
  293. 'chado_entity_id' => array(
  294. 'description' => 'The primary identifier for this table.',
  295. 'type' => 'serial',
  296. 'unsigned' => TRUE,
  297. 'not null' => TRUE,
  298. ),
  299. 'entity_id' => array(
  300. 'description' => 'The unique entity id.',
  301. 'type' => 'int',
  302. 'not null' => TRUE,
  303. ),
  304. 'record_id' => array(
  305. 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
  306. 'type' => 'int',
  307. 'not null' => TRUE,
  308. ),
  309. 'data_table' => array(
  310. 'description' => 'Indicates the table in Chado that this term services (e.g. feature, stock, library, etc.)',
  311. 'type' => 'varchar',
  312. 'length' => 128,
  313. 'not null' => TRUE,
  314. 'default' => '',
  315. ),
  316. 'type_table' => array(
  317. 'description' => 'Sometimes the record in the data table doesn’t have a field that specifies the record type. For example, an analysis type is stored in the analysisprop table. If the data_table does have a type field then this value will be the same as the data_table.',
  318. 'type' => 'varchar',
  319. 'length' => 128,
  320. 'not null' => TRUE,
  321. 'default' => '',
  322. ),
  323. 'field' => array(
  324. 'description' => 'The name of the field in the typetable that contains the cvterm record.',
  325. 'type' => 'varchar',
  326. 'length' => 128,
  327. 'not null' => FALSE,
  328. 'default' => ''
  329. ),
  330. ),
  331. 'indexes' => array(
  332. 'record_id' => array('record_id'),
  333. 'entity_id' => array('entity_id'),
  334. 'data_table' => array('data_table'),
  335. ),
  336. 'unique keys' => array(
  337. 'record' => array('data_table', 'record_id'),
  338. 'entity_id' => array('entity_id'),
  339. ),
  340. 'primary key' => array('chado_entity_id'),
  341. );
  342. return $schema;
  343. }