tripal_chado.install 23 KB

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