tripal_chado.install 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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. if (chado_is_installed()) {
  12. // For an upgraded site we need to move some vocabulary terms over
  13. // to the new 'local' vocabulary:
  14. tripal_insert_db(array(
  15. 'name' => 'local',
  16. 'description' => variable_get('site_name', 'This site.'),
  17. ));
  18. // Move the library properties out of the tripal database and into the
  19. // local database.
  20. $sql = "
  21. UPDATE {dbxref}
  22. SET db_id = (SELECT db_id FROM {db} WHERE name = 'local')
  23. WHERE dbxref_id IN (
  24. SELECT DISTINCT CVT.dbxref_id
  25. FROM {cvterm} CVT
  26. INNER JOIN {cv} CV ON CV.cv_id = CVT.cv_id
  27. WHERE CV.name IN (
  28. 'library_property',
  29. 'library_type',
  30. 'project_property',
  31. 'nd_experiment_types',
  32. 'nd_geolocation_property',
  33. 'tripal_analysis'
  34. )
  35. )
  36. ";
  37. chado_query($sql);
  38. }
  39. }
  40. /**
  41. * Implementation of hook_uninstall().
  42. *
  43. * @ingroup tripal
  44. */
  45. function tripal_chado_uninstall() {
  46. // // Drop the foreign key between tripal_custom_tables and tripal_mviews
  47. // // so that Drupal can then drop the tables
  48. // db_query('
  49. // ALTER TABLE {tripal_custom_tables}
  50. // DROP CONSTRAINT tripal_custom_tables_fk1 CASCADE
  51. // ');
  52. }
  53. function tripal_chado_chado_semweb_schema(){
  54. return array(
  55. 'fields' => array(
  56. 'chado_semweb_id' => array(
  57. 'type' => 'serial',
  58. 'not null' => TRUE
  59. ),
  60. 'chado_table' => array(
  61. 'type' => 'varchar',
  62. 'length ' => 128,
  63. 'not null' => TRUE
  64. ),
  65. 'chado_column' => array(
  66. 'type' => 'text',
  67. 'length ' => 128,
  68. 'not null' => TRUE
  69. ),
  70. 'cvterm_id' => array(
  71. 'type' => 'int',
  72. ),
  73. ),
  74. 'primary key' => array(
  75. 0 => 'chado_semweb_id',
  76. ),
  77. 'indexes' => array(
  78. 'chado_semweb_id_idx1' => array('cvterm_id'),
  79. 'chado_semweb_id_idx2' => array('chado_column'),
  80. 'chado_semweb_id_idx3' => array('chado_table'),
  81. ),
  82. 'unique keys' => array(
  83. 'chado_semweb_uq1' => array('chado_table', 'chado_column'),
  84. ),
  85. );
  86. }
  87. /**
  88. * Table definition for the tripal_cv_obo table
  89. * @param $schema
  90. */
  91. function tripal_chado_tripal_cv_obo_schema() {
  92. return array(
  93. 'fields' => array(
  94. 'obo_id' => array(
  95. 'type' => 'serial',
  96. 'unsigned' => TRUE,
  97. 'not null' => TRUE
  98. ),
  99. 'name' => array(
  100. 'type' => 'varchar',
  101. 'length' => 255
  102. ),
  103. 'path' => array(
  104. 'type' => 'varchar',
  105. 'length' => 1024
  106. ),
  107. ),
  108. 'indexes' => array(
  109. 'tripal_cv_obo_idx1' => array('obo_id'),
  110. ),
  111. 'primary key' => array('obo_id'),
  112. );
  113. }
  114. /**
  115. * * Table definition for the tripal_cv_defaults table
  116. * @param unknown $schema
  117. */
  118. function tripal_chado_tripal_cv_defaults_schema() {
  119. return array(
  120. 'fields' => array(
  121. 'cv_default_id' => array(
  122. 'type' => 'serial',
  123. 'unsigned' => TRUE,
  124. 'not null' => TRUE
  125. ),
  126. 'table_name' => array(
  127. 'type' => 'varchar',
  128. 'length' => 128,
  129. 'not null' => TRUE,
  130. ),
  131. 'field_name' => array(
  132. 'type' => 'varchar',
  133. 'length' => 128,
  134. 'not null' => TRUE,
  135. ),
  136. 'cv_id' => array(
  137. 'type' => 'int',
  138. 'not null' => TRUE,
  139. )
  140. ),
  141. 'indexes' => array(
  142. 'tripal_cv_defaults_idx1' => array('table_name', 'field_name'),
  143. ),
  144. 'unique keys' => array(
  145. 'tripal_cv_defaults_unq1' => array('table_name', 'field_name', 'cv_id'),
  146. ),
  147. 'primary key' => array('cv_default_id')
  148. );
  149. }
  150. /**
  151. *
  152. */
  153. function tripal_chado_enable() {
  154. // If Tripal v2 is already installed, then when the module is first enabled
  155. // after an upgade, the installation of this module will try and recreate
  156. // some of the tables created with tripal_core and the installation will fail.
  157. // Therefore, the tables were temporarily moved out of the way to preserve
  158. // the data. Now we'll move them back.
  159. tripal_chado_upgrade_v2_v3_enable();
  160. }
  161. /**
  162. * Implements hook_schema().
  163. */
  164. function tripal_chado_schema() {
  165. // If Tripal v2 is already installed, then when the module is first enabled
  166. // after an upgade, the installation of this module will try and recreate
  167. // some of the tables created with tripal_core and the installation will fail.
  168. // Therefore, we need to temporarily move those tables out of the way, let
  169. // the module install and then move them back.
  170. $migrated = variable_get('tripal_v2_upgrade_v3_check_chado', FALSE);
  171. if (!$migrated) {
  172. try {
  173. tripal_chado_upgrade_v2_v3_pre_enable();
  174. variable_set('tripal_v2_upgrade_v3_check_chado', TRUE);
  175. }
  176. catch(Exception $e) {
  177. watchdog_exception('tripal_chado', $e);
  178. }
  179. }
  180. // Links TripalEntity entities to the chado record.
  181. $schema['chado_entity'] = tripal_chado_chado_entity_schema();
  182. $schema['chado_semweb'] = tripal_chado_chado_semweb_schema();
  183. $schema['tripal_mviews'] = tripal_chado_tripal_mviews_schema();
  184. $schema['tripal_custom_tables'] = tripal_chado_tripal_custom_tables_schema();
  185. $schema['tripal_cv_obo'] = tripal_chado_tripal_cv_obo_schema();
  186. $schema['tripal_cv_defaults'] = tripal_chado_tripal_cv_defaults_schema();
  187. $schema['tripal_pub_import'] = tripal_chado_tripal_pub_import_schema();
  188. // if this module is already installed and enabled, then we want to provide
  189. // the schemas for all of the custom tables. This will allow Views to
  190. // see the schemas. We check if the module is installed because during
  191. // installation we don't want to make these custom tables available as we don't
  192. // want them created in the Drupal database. The custom tables go in the
  193. // Chado database.
  194. if (db_table_exists('tripal_custom_tables')) {
  195. $sql = 'SELECT * FROM {tripal_custom_tables}';
  196. $results = db_query($sql);
  197. foreach ($results as $custom) {
  198. $schema[$custom->table_name] = unserialize($custom->schema);
  199. }
  200. }
  201. // Map cvterm usage to chado tables
  202. $schema['tripal_cvterm_mapping'] = tripal_chado_tripal_cvterm_mapping_schema();
  203. return $schema;
  204. }
  205. /**
  206. * This function should be executed only one time during upgrade of v2 to v3.
  207. */
  208. function tripal_chado_upgrade_v2_v3_pre_enable() {
  209. // If Tripal v2 is already installed, then when the module is first enabled
  210. // after an upgade, the installation of this module will try and recreate
  211. // some of the tables created with tripal_core and the installation will fail.
  212. // Therefore, we need to temporarily move those tables out of the way, let
  213. // the module install and then move them back.
  214. if (db_table_exists('tripal_mviews')) {
  215. // Move the tripal_mviews table out of the way.
  216. $sql = "ALTER TABLE tripal_mviews RENAME TO tripal_mviews2";
  217. db_query($sql);
  218. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_name_key'")->fetchField()) {
  219. $sql = "ALTER INDEX tripal_mviews_mv_name_key RENAME TO tripal_mviews_mv_name_key2";
  220. }
  221. else {
  222. $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_name_key2 ON tripal_mviews2 USING btree (name)";
  223. }
  224. db_query($sql);
  225. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_table_key'")->fetchField()) {
  226. $sql = "ALTER INDEX tripal_mviews_mv_table_key RENAME TO tripal_mviews_mv_table_key2";
  227. }
  228. else {
  229. $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_table_key2 ON tripal_mviews2 USING btree (mv_table)";
  230. }
  231. db_query($sql);
  232. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mview_id_idx'")->fetchField()) {
  233. $sql = "ALTER INDEX tripal_mviews_mview_id_idx RENAME TO tripal_mviews_mview_id_idx2";
  234. }
  235. else {
  236. $sql = "CREATE INDEX tripal_mviews_mview_id_idx2 ON tripal_mviews2 USING btree (mview_id)";
  237. }
  238. db_query($sql);
  239. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_pkey'")->fetchField()) {
  240. $sql = "ALTER INDEX tripal_mviews_pkey RENAME TO tripal_mviews_pkey2";
  241. }
  242. else {
  243. $sql = "CREATE UNIQUE INDEX tripal_mviews_pkey2 ON tripal_mviews2 USING btree (mview_id)";
  244. }
  245. db_query($sql);
  246. }
  247. if (db_table_exists('tripal_custom_tables')) {
  248. // Move the tripal_custom_tables table out of the way.
  249. $sql = "ALTER TABLE tripal_custom_tables RENAME TO tripal_custom_tables2";
  250. db_query($sql);
  251. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_pkey'")->fetchField()) {
  252. $sql = "ALTER INDEX tripal_custom_tables_pkey RENAME TO tripal_custom_tables_pkey2";
  253. }
  254. else {
  255. $sql = "CREATE UNIQUE INDEX tripal_custom_tables_pkey2 ON tripal_custom_tables2 USING btree (table_id)";
  256. }
  257. db_query($sql);
  258. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_table_id_idx'")->fetchField()) {
  259. $sql = "ALTER INDEX tripal_custom_tables_table_id_idx RENAME TO tripal_custom_tables_table_id_idx2";
  260. }
  261. else {
  262. $sql = "CREATE INDEX tripal_custom_tables_table_id_idx2 ON tripal_custom_tables2 USING btree (table_id)";
  263. }
  264. db_query($sql);
  265. }
  266. if (db_table_exists('tripal_cv_obo')) {
  267. // Move the tripal_cv_obo table out of the way.
  268. $sql = "ALTER TABLE tripal_cv_obo RENAME TO tripal_cv_obo2";
  269. db_query($sql);
  270. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_obo_id_idx'")->fetchField()) {
  271. $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx RENAME TO tripal_cv_obo_obo_id_idx2";
  272. }
  273. else {
  274. $sql = "CREATE INDEX tripal_cv_obo_obo_id_idx2 ON tripal_cv_obo2 USING btree (obo_id)";
  275. }
  276. db_query($sql);
  277. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_pkey'")->fetchField()) {
  278. $sql = "ALTER INDEX tripal_cv_obo_pkey RENAME TO tripal_cv_obo_pkey2";
  279. }
  280. else {
  281. $sql = "CREATE UNIQUE INDEX tripal_cv_obo_pkey2 ON tripal_cv_obo2 USING btree (obo_id)";
  282. }
  283. db_query($sql);
  284. }
  285. if (db_table_exists('tripal_cv_defaults')) {
  286. // Move the tripal_cv_defaults table out of the way.
  287. $sql = "ALTER TABLE tripal_cv_defaults RENAME TO tripal_cv_defaults2";
  288. db_query($sql);
  289. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_defaults_pkey'")->fetchField()) {
  290. $sql = "ALTER INDEX tripal_cv_defaults_pkey RENAME TO tripal_cv_defaults_pkey2";
  291. }
  292. else {
  293. $sql = "CREATE UNIQUE INDEX tripal_cv_defaults_pkey2 ON tripal_cv_defaults2 USING btree (cv_default_id)";
  294. }
  295. db_query($sql);
  296. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_defaults_tripal_cv_defaults_idx1_idx'")->fetchField()) {
  297. $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_idx1_idx RENAME TO tripal_cv_defaults_tripal_cv_defaults_idx1_idx2";
  298. }
  299. else {
  300. $sql = "CREATE INDEX tripal_cv_defaults_tripal_cv_defaults_idx1_idx2 ON tripal_cv_defaults2 USING btree (table_name, field_name)";
  301. }
  302. db_query($sql);
  303. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_defaults_tripal_cv_defaults_unq1_key'")->fetchField()) {
  304. $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_unq1_key RENAME TO tripal_cv_defaults_tripal_cv_defaults_unq1_key2";
  305. }
  306. else {
  307. $sql = "CREATE UNIQUE INDEX tripal_cv_defaults_tripal_cv_defaults_unq1_key2 ON tripal_cv_defaults2 USING btree (table_name, field_name, cv_id)";
  308. }
  309. db_query($sql);
  310. }
  311. if (db_table_exists('tripal_pub_import')) {
  312. // Move the tripal_pub_import table out of the way.
  313. $sql = "ALTER TABLE tripal_pub_import RENAME TO tripal_pub_import2";
  314. db_query($sql);
  315. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_name_idx'")->fetchField()) {
  316. $sql = "ALTER INDEX tripal_pub_import_name_idx RENAME TO tripal_pub_import_name_idx2";
  317. }
  318. else {
  319. $sql = "CREATE INDEX tripal_pub_import_name_idx2 ON tripal_pub_import2 USING btree (name)";
  320. }
  321. db_query($sql);
  322. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_pkey'")->fetchField()) {
  323. $sql = "ALTER INDEX tripal_pub_import_pkey RENAME TO tripal_pub_import_pkey2";
  324. }
  325. else {
  326. $sql = "CREATE UNIQUE INDEX tripal_pub_import_pkey2 ON tripal_pub_import2 USING btree (pub_import_id)";
  327. }
  328. db_query($sql);
  329. }
  330. }
  331. /**
  332. * This function should be executed only one time during upgrade of v2 to v3.
  333. */
  334. function tripal_chado_upgrade_v2_v3_enable() {
  335. // If Tripal v2 is already installed, the installation of this module
  336. // will try and recreate some of the tables created with tripal_core and the
  337. // installation will fail. Therefore, in the install we renamed it. Now
  338. // we want to move it back.
  339. if (db_table_exists('tripal_mviews2')) {
  340. // tripal_mviews
  341. $sql = "DROP TABLE tripal_mviews";
  342. db_query($sql);
  343. $sql = "ALTER TABLE tripal_mviews2 RENAME to tripal_mviews";
  344. db_query($sql);
  345. $sql = "ALTER INDEX tripal_mviews_mv_name_key2 RENAME TO tripal_mviews_mv_name_key";
  346. db_query($sql);
  347. $sql = "ALTER INDEX tripal_mviews_mv_table_key2 RENAME TO tripal_mviews_mv_table_key";
  348. db_query($sql);
  349. $sql = "ALTER INDEX tripal_mviews_mview_id_idx2 RENAME TO tripal_mviews_mview_id_idx";
  350. db_query($sql);
  351. $sql = "ALTER INDEX tripal_mviews_pkey2 RENAME TO tripal_mviews_pkey";
  352. db_query($sql);
  353. }
  354. // tripal_custom_tables
  355. if (db_table_exists('tripal_custom_tables2')) {
  356. $sql = "DROP TABLE tripal_custom_tables";
  357. db_query($sql);
  358. $sql = "ALTER TABLE tripal_custom_tables2 RENAME to tripal_custom_tables";
  359. db_query($sql);
  360. $sql = "ALTER INDEX tripal_custom_tables_pkey2 RENAME TO tripal_custom_tables_pkey";
  361. db_query($sql);
  362. $sql = "ALTER INDEX tripal_custom_tables_table_id_idx2 RENAME TO tripal_custom_tables_table_id_idx";
  363. db_query($sql);
  364. }
  365. // tripal_cv_obo
  366. if (db_table_exists('tripal_cv_obo2')) {
  367. $sql = "DROP TABLE tripal_cv_obo";
  368. db_query($sql);
  369. $sql = "ALTER TABLE tripal_cv_obo2 RENAME to tripal_cv_obo";
  370. db_query($sql);
  371. $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx2 RENAME TO tripal_cv_obo_obo_id_idx";
  372. db_query($sql);
  373. $sql = "ALTER INDEX tripal_cv_obo_pkey2 RENAME TO tripal_cv_obo_pkey";
  374. db_query($sql);
  375. }
  376. // tripal_cv_defaults
  377. if (db_table_exists('tripal_cv_defaults2')) {
  378. $sql = "DROP TABLE tripal_cv_defaults";
  379. db_query($sql);
  380. $sql = "ALTER TABLE tripal_cv_defaults2 RENAME to tripal_cv_defaults";
  381. db_query($sql);
  382. $sql = "ALTER INDEX tripal_cv_defaults_pkey2 RENAME TO tripal_cv_defaults_pkey";
  383. db_query($sql);
  384. $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_idx1_idx2 RENAME TO tripal_cv_defaults_tripal_cv_defaults_idx1_idx";
  385. db_query($sql);
  386. $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_unq1_key2 RENAME TO tripal_cv_defaults_tripal_cv_defaults_unq1_key";
  387. db_query($sql);
  388. }
  389. // tripal_pub_import
  390. if (db_table_exists('tripal_pub_import2')) {
  391. $sql = "DROP TABLE tripal_pub_import";
  392. db_query($sql);
  393. $sql = "ALTER TABLE tripal_pub_import2 RENAME to tripal_pub_import";
  394. db_query($sql);
  395. $sql = "ALTER INDEX tripal_pub_import_name_idx2 RENAME TO tripal_pub_import_name_idx";
  396. db_query($sql);
  397. $sql = "ALTER INDEX tripal_pub_import_pkey2 RENAME TO tripal_pub_import_pkey";
  398. db_query($sql);
  399. }
  400. }
  401. /**
  402. * @section
  403. * Schema Definitions.
  404. */
  405. /**
  406. * Implementation of hook_schema().
  407. *
  408. * @ingroup tripal_pub
  409. */
  410. function tripal_chado_tripal_pub_import_schema() {
  411. return array(
  412. 'fields' => array(
  413. 'pub_import_id' => array(
  414. 'type' => 'serial',
  415. 'not null' => TRUE
  416. ),
  417. 'name' => array(
  418. 'type' => 'varchar',
  419. 'length' => 255,
  420. 'not null' => TRUE
  421. ),
  422. 'criteria' => array(
  423. 'type' => 'text',
  424. 'size' => 'normal',
  425. 'not null' => TRUE,
  426. 'description' => 'Contains a serialized PHP array containing the search criteria'
  427. ),
  428. 'disabled' => array(
  429. 'type' => 'int',
  430. 'unsigned' => TRUE,
  431. 'not NULL' => TRUE,
  432. 'default' => 0
  433. ),
  434. 'do_contact' => array(
  435. 'type' => 'int',
  436. 'unsigned' => TRUE,
  437. 'not NULL' => TRUE,
  438. 'default' => 0
  439. ),
  440. ),
  441. 'primary key' => array('pub_import_id'),
  442. 'indexes' => array(
  443. 'name' => array('name')
  444. ),
  445. );
  446. }
  447. /**
  448. * Describes the Tripal Custom Tables (tripal_custom_tables) table
  449. * This keeps track of tables created by Tripal and stored in chado that may or may not
  450. * also be materialized views.
  451. *
  452. * @ingroup tripal
  453. */
  454. function tripal_chado_tripal_custom_tables_schema() {
  455. return array(
  456. 'fields' => array(
  457. 'table_id' => array(
  458. 'type' => 'serial',
  459. 'unsigned' => TRUE,
  460. 'not NULL' => TRUE
  461. ),
  462. 'table_name' => array(
  463. 'type' => 'varchar',
  464. 'length' => 255,
  465. 'not NULL' => TRUE
  466. ),
  467. 'schema' => array(
  468. 'type' => 'text',
  469. 'not NULL' => TRUE
  470. ),
  471. 'mview_id' => array(
  472. 'type' => 'int',
  473. 'not NULL' => FALSE
  474. )
  475. ),
  476. 'indexes' => array(
  477. 'table_id' => array('table_id'),
  478. ),
  479. 'primary key' => array('table_id'),
  480. 'foreign keys' => array(
  481. 'tripal_mviews' => array(
  482. 'table' => 'tripal_mviews',
  483. 'columns' => array(
  484. 'mview_id' => 'mview_id'
  485. ),
  486. ),
  487. ),
  488. );
  489. }
  490. /**
  491. * Describes the Tripal Materialized View (tripal_mviews) table
  492. * This table keeps track of all materialized views created by Tripal and stored in chado
  493. *
  494. * @ingroup tripal
  495. */
  496. function tripal_chado_tripal_mviews_schema() {
  497. return array(
  498. 'fields' => array(
  499. 'mview_id' => array(
  500. 'type' => 'serial',
  501. 'unsigned' => TRUE,
  502. 'not NULL' => TRUE
  503. ),
  504. 'name' => array(
  505. 'type' => 'varchar',
  506. 'length' => 255,
  507. 'not NULL' => TRUE
  508. ),
  509. 'modulename' => array(
  510. 'type' => 'varchar',
  511. 'length' => 50,
  512. 'not NULL' => TRUE,
  513. 'description' => 'The module name that provides the callback for this job'
  514. ),
  515. 'mv_table' => array(
  516. 'type' => 'varchar',
  517. 'length' => 128,
  518. 'not NULL' => FALSE
  519. ),
  520. 'mv_specs' => array(
  521. 'type' => 'text',
  522. 'size' => 'normal',
  523. 'not NULL' => FALSE
  524. ),
  525. 'mv_schema' => array(
  526. 'type' => 'text',
  527. 'size' => 'normal',
  528. 'not NULL' => FALSE
  529. ),
  530. 'indexed' => array(
  531. 'type' => 'text',
  532. 'size' => 'normal',
  533. 'not NULL' => FALSE
  534. ),
  535. 'query' => array(
  536. 'type' => 'text',
  537. 'size' => 'normal',
  538. 'not NULL' => TRUE
  539. ),
  540. 'special_index' => array(
  541. 'type' => 'text',
  542. 'size' => 'normal',
  543. 'not NULL' => FALSE
  544. ),
  545. 'last_update' => array(
  546. 'type' => 'int',
  547. 'not NULL' => FALSE,
  548. 'description' => 'UNIX integer time'
  549. ),
  550. 'status' => array(
  551. 'type' => 'text',
  552. 'size' => 'normal',
  553. 'not NULL' => FALSE
  554. ),
  555. 'comment' => array(
  556. 'type' => 'text',
  557. 'size' => 'normal',
  558. 'not NULL' => FALSE
  559. ),
  560. ),
  561. 'indexes' => array(
  562. 'mview_id' => array('mview_id')
  563. ),
  564. 'unique keys' => array(
  565. 'mv_table' => array('mv_table'),
  566. 'mv_name' => array('name'),
  567. ),
  568. 'primary key' => array('mview_id'),
  569. );
  570. }
  571. /**
  572. * Links Biological Data Entities to the chado "base" table the data is stored in.
  573. * This is where we would specify that a particular gene maps to the record in the
  574. * chado.feature table with a feature_id=2432;
  575. */
  576. function tripal_chado_chado_entity_schema() {
  577. $schema = array(
  578. 'description' => 'The linker table that associates an enitity from the public.tripal_entity table with a "base" record in Chado',
  579. 'fields' => array(
  580. 'chado_entity_id' => array(
  581. 'description' => 'The primary identifier for this table.',
  582. 'type' => 'serial',
  583. 'unsigned' => TRUE,
  584. 'not null' => TRUE,
  585. ),
  586. 'entity_id' => array(
  587. 'description' => 'The unique entity id.',
  588. 'type' => 'int',
  589. 'not null' => TRUE,
  590. ),
  591. 'record_id' => array(
  592. 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
  593. 'type' => 'int',
  594. 'not null' => TRUE,
  595. ),
  596. 'data_table' => array(
  597. 'description' => 'Indicates the table in Chado that this term services (e.g. feature, stock, library, etc.)',
  598. 'type' => 'varchar',
  599. 'length' => 128,
  600. 'not null' => TRUE,
  601. 'default' => '',
  602. ),
  603. 'type_table' => array(
  604. '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.',
  605. 'type' => 'varchar',
  606. 'length' => 128,
  607. 'not null' => TRUE,
  608. 'default' => '',
  609. ),
  610. 'field' => array(
  611. 'description' => 'The name of the field in the typetable that contains the cvterm record.',
  612. 'type' => 'varchar',
  613. 'length' => 128,
  614. 'not null' => FALSE,
  615. 'default' => ''
  616. ),
  617. 'nid' => array(
  618. 'description' => 'Optional. For linking nid to the entity when migrating Tripal v2 content',
  619. 'type' => 'int',
  620. )
  621. ),
  622. 'indexes' => array(
  623. 'record_id' => array('record_id'),
  624. 'entity_id' => array('entity_id'),
  625. 'data_table' => array('data_table'),
  626. 'nid' => array('nid'),
  627. ),
  628. 'unique keys' => array(
  629. 'record' => array('data_table', 'record_id'),
  630. 'entity_id' => array('entity_id'),
  631. ),
  632. 'primary key' => array('chado_entity_id'),
  633. );
  634. return $schema;
  635. }
  636. /**
  637. * Tripal cvterm mapping schema
  638. * Map cvterms to chado tables that use them
  639. */
  640. function tripal_chado_tripal_cvterm_mapping_schema() {
  641. $schema = array (
  642. 'table' => 'tripal_cvterm_mapping',
  643. 'fields' => array (
  644. 'mapping_id' => array(
  645. 'type' => 'serial',
  646. 'not null' => TRUE
  647. ),
  648. 'cvterm_id' => array (
  649. 'type' => 'int',
  650. 'not null' => TRUE
  651. ),
  652. 'chado_table' => array (
  653. 'type' => 'varchar',
  654. 'length' => 128,
  655. 'not null' => TRUE
  656. ),
  657. 'chado_field' => array (
  658. 'type' => 'varchar',
  659. 'length' => 128,
  660. 'not null' => TRUE
  661. ),
  662. ),
  663. 'primary key' => array (
  664. 0 => 'mapping_id'
  665. ),
  666. 'indexes' => array(
  667. 'tripal_cvterm2table_idx1' => array('cvterm_id'),
  668. 'tripal_cvterm2table_idx2' => array('chado_table'),
  669. 'tripal_cvterm2table_idx3' => array('chado_table', 'chado_field'),
  670. ),
  671. );
  672. return $schema;
  673. }