tripal_chado.install 21 KB

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