tripal_chado.install 22 KB

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