tripal_chado.install 24 KB

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