tripal_chado.install 20 KB

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