tripal_entities.install 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. /**
  3. * @file
  4. * Install for a tripal data entity - creates the base table for our entity.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function tripal_entities_schema() {
  10. // Adds a table for managing TripalEntity entities.
  11. $schema['tripal_vocab'] = tripal_entities_tripal_vocab_schema();
  12. $schema['tripal_term'] = tripal_entities_tripal_term_schema();
  13. $schema['tripal_entity'] = tripal_entities_tripal_entity_schema();
  14. $schema['tripal_bundle'] = tripal_entities_tripal_bundle_schema();
  15. // Adds a table for additional information related to bundles.
  16. $schema['tripal_bundle_variables'] = tripal_entities_tripal_bundle_variables_schema();
  17. return $schema;
  18. }
  19. /**
  20. * @section
  21. * Schema Definitions.
  22. */
  23. /**
  24. * The base table for Biological Data Entities.
  25. *
  26. * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then
  27. * this table will have 15 records and include both genes and mRNA's.
  28. */
  29. function tripal_entities_tripal_entity_schema() {
  30. $schema = array(
  31. 'description' => 'The base table for Tripal Vocabulary-based entities.',
  32. 'fields' => array(
  33. 'id' => array(
  34. 'description' => 'The primary identifier for a vocabulary entity.',
  35. 'type' => 'serial',
  36. 'unsigned' => TRUE,
  37. 'not null' => TRUE,
  38. ),
  39. 'type' => array(
  40. 'description' => 'The type of entity. This should be an official vocabulary ID (e.g. SO, RO, GO).',
  41. 'type' => 'varchar',
  42. 'length' => 64,
  43. 'not null' => TRUE,
  44. 'default' => '',
  45. ),
  46. 'bundle' => array(
  47. 'description' => 'The type of bundle. This should be an official vocabulary ID (e.g. SO, RO, GO) followed by an underscore and the term accession.',
  48. 'type' => 'varchar',
  49. 'length' => 1024,
  50. 'not null' => TRUE,
  51. 'default' => '',
  52. ),
  53. 'term_id' => array(
  54. 'description' => 'The term_id for the type of entity. This term_id corresponds to a TripalTerm record.',
  55. 'type' => 'int',
  56. 'not null' => TRUE,
  57. ),
  58. 'title' => array(
  59. 'description' => 'The title of this node, always treated as non-markup plain text.',
  60. 'type' => 'text',
  61. 'not null' => TRUE,
  62. 'default' => '',
  63. ),
  64. 'uid' => array(
  65. 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
  66. 'type' => 'int',
  67. 'not null' => TRUE,
  68. 'default' => 0,
  69. ),
  70. 'status' => array(
  71. 'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
  72. 'type' => 'int',
  73. 'not null' => TRUE,
  74. 'default' => 1,
  75. ),
  76. 'created' => array(
  77. 'description' => 'The Unix timestamp when the node was created.',
  78. 'type' => 'int',
  79. 'not null' => TRUE,
  80. 'default' => 0,
  81. ),
  82. 'changed' => array(
  83. 'description' => 'The Unix timestamp when the node was most recently saved.',
  84. 'type' => 'int',
  85. 'not null' => TRUE,
  86. 'default' => 0,
  87. ),
  88. ),
  89. 'indexes' => array(
  90. 'term_id' => array('term_id'),
  91. 'entity_changed' => array('changed'),
  92. 'entity_created' => array('created'),
  93. 'type' => array('type'),
  94. 'uid' => array('uid'),
  95. ),
  96. 'unique keys' => array(),
  97. 'primary key' => array('id'),
  98. );
  99. return $schema;
  100. }
  101. /**
  102. * The base table for TripalVocab schema.
  103. *
  104. * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then
  105. * this table will have 15 records and include both genes and mRNA's.
  106. */
  107. function tripal_entities_tripal_vocab_schema() {
  108. // This schema only provides enough information to assign a unique ID
  109. // to the vocabulary. Any additonal information is added to the Entity object
  110. // by the selected database back-end.
  111. $schema = array(
  112. 'description' => 'The base table for TripalVocab entities.',
  113. 'fields' => array(
  114. 'id' => array(
  115. 'description' => 'The primary identifier for a vocab entity.',
  116. 'type' => 'serial',
  117. 'unsigned' => TRUE,
  118. 'not null' => TRUE,
  119. ),
  120. 'namespace' => array(
  121. 'description' => 'The namespace for the vocabulary (e.g. SO, PATO, etc.).',
  122. 'type' => 'varchar',
  123. 'length' => 10,
  124. 'not null' => TRUE,
  125. ),
  126. 'created' => array(
  127. 'description' => 'The Unix timestamp when the entity was created.',
  128. 'type' => 'int',
  129. 'not null' => TRUE,
  130. 'default' => 0,
  131. ),
  132. 'changed' => array(
  133. 'description' => 'The Unix timestamp when the entity was most recently saved.',
  134. 'type' => 'int',
  135. 'not null' => TRUE,
  136. 'default' => 0,
  137. ),
  138. ),
  139. 'indexes' => array(
  140. 'namespace' => array('namespace'),
  141. 'entity_changed' => array('changed'),
  142. 'entity_created' => array('created'),
  143. ),
  144. 'unique keys' => array('namespace' => array('namespace')),
  145. 'primary key' => array('id'),
  146. );
  147. return $schema;
  148. }
  149. /**
  150. * The base table for TripalTerm entities.
  151. *
  152. * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then
  153. * this table will have 15 records and include both genes and mRNA's.
  154. */
  155. function tripal_entities_tripal_term_schema() {
  156. // This schema only provides enough information to assign a unique ID
  157. // to the term and associate it to it's vocabulary. Any additonal information
  158. // is added to the Entity object by the selected database back-end.
  159. $schema = array(
  160. 'description' => 'The base table for TripalTerm entities.',
  161. 'fields' => array(
  162. 'id' => array(
  163. 'description' => 'The primary identifier for a term entity.',
  164. 'type' => 'serial',
  165. 'unsigned' => TRUE,
  166. 'not null' => TRUE,
  167. ),
  168. 'vocab_id' => array(
  169. 'description' => 'The vocabulary_id of the TripalVocab entity to which this term belongs.',
  170. 'type' => 'int',
  171. 'not null' => TRUE,
  172. ),
  173. 'term_id' => array(
  174. 'description' => 'The id (or accession) of this term in the vocabulary.',
  175. 'type' => 'varchar',
  176. 'length' => 1024,
  177. 'not null' => TRUE,
  178. 'default' => '',
  179. ),
  180. 'name' => array(
  181. 'description' => 'The human readable name for this term.',
  182. 'type' => 'varchar',
  183. 'length' => 1024,
  184. 'not null' => TRUE,
  185. 'default' => '',
  186. ),
  187. 'created' => array(
  188. 'description' => 'The Unix timestamp when the entity was created.',
  189. 'type' => 'int',
  190. 'not null' => TRUE,
  191. 'default' => 0,
  192. ),
  193. 'changed' => array(
  194. 'description' => 'The Unix timestamp when the entity was most recently saved.',
  195. 'type' => 'int',
  196. 'not null' => TRUE,
  197. 'default' => 0,
  198. ),
  199. ),
  200. 'indexes' => array(
  201. 'vocab_id' => array('vocab_id'),
  202. 'term_id' => array('term_id'),
  203. 'entity_changed' => array('changed'),
  204. 'entity_created' => array('created'),
  205. ),
  206. 'foreign keys' => array(
  207. 'tripal_vocab' => array(
  208. 'table' => 'tripal_vocab',
  209. 'columns' => array(
  210. 'vocab_id' => 'vocab_id',
  211. ),
  212. ),
  213. ),
  214. 'unique keys' => array('vocab_term' => array('vocab_id', 'term_id')),
  215. 'primary key' => array('id'),
  216. );
  217. return $schema;
  218. }
  219. /**
  220. * The base table for TripalEntity entities.
  221. *
  222. * This table contains a list of Biological Data Types.
  223. * For the example above (5 genes and 10 mRNAs), there would only be two records in
  224. * this table one for "gene" and another for "mRNA".
  225. */
  226. function tripal_entities_tripal_bundle_schema() {
  227. $schema = array(
  228. 'description' => 'Stores information about defined tripal data types.',
  229. 'fields' => array(
  230. 'id' => array(
  231. 'type' => 'serial',
  232. 'not null' => TRUE,
  233. 'description' => 'Primary Key: Unique numeric ID.',
  234. ),
  235. 'type' => array(
  236. 'description' => 'The type of entity. This should be an official vocabulary ID (e.g. SO, RO, GO).',
  237. 'type' => 'varchar',
  238. 'length' => 64,
  239. 'not null' => TRUE,
  240. 'default' => '',
  241. ),
  242. 'bundle' => array(
  243. 'description' => 'The type of bundle. This should be an official vocabulary ID (e.g. SO, RO, GO) followed by an underscore and the term accession.',
  244. 'type' => 'varchar',
  245. 'length' => 1024,
  246. 'not null' => TRUE,
  247. 'default' => '',
  248. ),
  249. 'label' => array(
  250. 'description' => 'The human-readable name of this bundle.',
  251. 'type' => 'varchar',
  252. 'length' => 255,
  253. 'not null' => TRUE,
  254. 'default' => '',
  255. ),
  256. ),
  257. 'primary key' => array('id'),
  258. 'unique keys' => array(
  259. 'bundle' => array('bundle'),
  260. ),
  261. );
  262. return $schema;
  263. }
  264. /**
  265. * Additional Tripal Bundle Information.
  266. *
  267. * This table is used for storing any additonal information describing
  268. * a tripal bundle. For example, this is a good place to store title/url formats.
  269. */
  270. function tripal_entities_tripal_bundle_variables_schema() {
  271. $schema = array(
  272. 'description' => 'This table is used for storing any additonal information describing
  273. a tripal bundle. For example, this is a good place to store title/url formats.',
  274. 'fields' => array (
  275. 'bundle_variable_id' => array (
  276. 'type' => 'serial',
  277. 'not null' => TRUE,
  278. ),
  279. 'bundle_id' => array (
  280. 'type' => 'int',
  281. 'not null' => TRUE,
  282. ),
  283. 'variable_id' => array (
  284. 'type' => 'int',
  285. 'not null' => TRUE,
  286. ),
  287. 'value' => array (
  288. 'type' => 'text',
  289. 'not null' => FALSE,
  290. ),
  291. 'rank' => array (
  292. 'type' => 'int',
  293. 'not null' => TRUE,
  294. 'default' => 0,
  295. ),
  296. ),
  297. 'primary key' => array (
  298. 0 => 'bundle_variable_id',
  299. ),
  300. 'unique keys' => array (
  301. 'tripal_bundle_variables_c1' => array (
  302. 0 => 'bundle_id',
  303. 1 => 'variable_id',
  304. 2 => 'rank',
  305. ),
  306. ),
  307. 'indexes' => array (
  308. 'tripal_bundle_variables_idx1' => array (
  309. 0 => 'variable_id',
  310. ),
  311. ),
  312. 'foreign keys' => array (
  313. 'tripal_variables' => array (
  314. 'table' => 'tripal_variables',
  315. 'columns' => array (
  316. 'variable_id' => 'variable_id',
  317. ),
  318. ),
  319. ),
  320. );
  321. return $schema;
  322. }