tripal_chado.install 21 KB

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