tripal_entities.install 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. return $schema;
  16. }
  17. /**
  18. * @section
  19. * Schema Definitions.
  20. */
  21. /**
  22. * The base table for Biological Data Entities.
  23. *
  24. * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then
  25. * this table will have 15 records and include both genes and mRNA's.
  26. */
  27. function tripal_entities_tripal_entity_schema() {
  28. $schema = array(
  29. 'description' => 'The base table for Tripal Vocabulary-based entities.',
  30. 'fields' => array(
  31. 'id' => array(
  32. 'description' => 'The primary identifier for a vocabulary entity.',
  33. 'type' => 'serial',
  34. 'unsigned' => TRUE,
  35. 'not null' => TRUE,
  36. ),
  37. 'type' => array(
  38. 'description' => 'The type of entity. This should be an official vocabulary ID (e.g. SO, RO, GO).',
  39. 'type' => 'varchar',
  40. 'length' => 64,
  41. 'not null' => TRUE,
  42. 'default' => '',
  43. ),
  44. 'bundle' => array(
  45. '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.',
  46. 'type' => 'varchar',
  47. 'length' => 1024,
  48. 'not null' => TRUE,
  49. 'default' => '',
  50. ),
  51. 'term_id' => array(
  52. 'description' => 'The term_id for the type of entity. This term_id corresponds to a TripalTerm record.',
  53. 'type' => 'int',
  54. 'not null' => TRUE,
  55. ),
  56. 'title' => array(
  57. 'description' => 'The title of this node, always treated as non-markup plain text.',
  58. 'type' => 'text',
  59. 'not null' => TRUE,
  60. 'default' => '',
  61. ),
  62. 'uid' => array(
  63. 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
  64. 'type' => 'int',
  65. 'not null' => TRUE,
  66. 'default' => 0,
  67. ),
  68. 'status' => array(
  69. 'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
  70. 'type' => 'int',
  71. 'not null' => TRUE,
  72. 'default' => 1,
  73. ),
  74. 'created' => array(
  75. 'description' => 'The Unix timestamp when the node was created.',
  76. 'type' => 'int',
  77. 'not null' => TRUE,
  78. 'default' => 0,
  79. ),
  80. 'changed' => array(
  81. 'description' => 'The Unix timestamp when the node was most recently saved.',
  82. 'type' => 'int',
  83. 'not null' => TRUE,
  84. 'default' => 0,
  85. ),
  86. ),
  87. 'indexes' => array(
  88. 'term_id' => array('term_id'),
  89. 'entity_changed' => array('changed'),
  90. 'entity_created' => array('created'),
  91. 'type' => array('type'),
  92. 'uid' => array('uid'),
  93. ),
  94. 'unique keys' => array(),
  95. 'primary key' => array('id'),
  96. );
  97. return $schema;
  98. }
  99. /**
  100. * The base table for TripalVocab schema.
  101. *
  102. * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then
  103. * this table will have 15 records and include both genes and mRNA's.
  104. */
  105. function tripal_entities_tripal_vocab_schema() {
  106. // This schema only provides enough information to assign a unique ID
  107. // to the vocabulary. Any additonal information is added to the Entity object
  108. // by the selected database back-end.
  109. $schema = array(
  110. 'description' => 'The base table for TripalVocab entities.',
  111. 'fields' => array(
  112. 'id' => array(
  113. 'description' => 'The primary identifier for a vocab entity.',
  114. 'type' => 'serial',
  115. 'unsigned' => TRUE,
  116. 'not null' => TRUE,
  117. ),
  118. 'namespace' => array(
  119. 'description' => 'The namespace for the vocabulary (e.g. SO, PATO, etc.).',
  120. 'type' => 'varchar',
  121. 'length' => 10,
  122. 'not null' => TRUE,
  123. ),
  124. 'created' => array(
  125. 'description' => 'The Unix timestamp when the entity was created.',
  126. 'type' => 'int',
  127. 'not null' => TRUE,
  128. 'default' => 0,
  129. ),
  130. 'changed' => array(
  131. 'description' => 'The Unix timestamp when the entity was most recently saved.',
  132. 'type' => 'int',
  133. 'not null' => TRUE,
  134. 'default' => 0,
  135. ),
  136. ),
  137. 'indexes' => array(
  138. 'namespace' => array('namespace'),
  139. 'entity_changed' => array('changed'),
  140. 'entity_created' => array('created'),
  141. ),
  142. 'unique keys' => array('namespace' => array('namespace')),
  143. 'primary key' => array('id'),
  144. );
  145. return $schema;
  146. }
  147. /**
  148. * The base table for TripalTerm entities.
  149. *
  150. * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then
  151. * this table will have 15 records and include both genes and mRNA's.
  152. */
  153. function tripal_entities_tripal_term_schema() {
  154. // This schema only provides enough information to assign a unique ID
  155. // to the term and associate it to it's vocabulary. Any additonal information
  156. // is added to the Entity object by the selected database back-end.
  157. $schema = array(
  158. 'description' => 'The base table for TripalTerm entities.',
  159. 'fields' => array(
  160. 'id' => array(
  161. 'description' => 'The primary identifier for a term entity.',
  162. 'type' => 'serial',
  163. 'unsigned' => TRUE,
  164. 'not null' => TRUE,
  165. ),
  166. 'vocab_id' => array(
  167. 'description' => 'The vocabulary_id of the TripalVocab entity to which this term belongs.',
  168. 'type' => 'int',
  169. 'not null' => TRUE,
  170. ),
  171. 'term_id' => array(
  172. 'description' => 'The id (or accession) of this term in the vocabulary.',
  173. 'type' => 'varchar',
  174. 'length' => 1024,
  175. 'not null' => TRUE,
  176. 'default' => '',
  177. ),
  178. 'name' => array(
  179. 'description' => 'The human readable name for this term.',
  180. 'type' => 'varchar',
  181. 'length' => 1024,
  182. 'not null' => TRUE,
  183. 'default' => '',
  184. ),
  185. 'created' => array(
  186. 'description' => 'The Unix timestamp when the entity was created.',
  187. 'type' => 'int',
  188. 'not null' => TRUE,
  189. 'default' => 0,
  190. ),
  191. 'changed' => array(
  192. 'description' => 'The Unix timestamp when the entity was most recently saved.',
  193. 'type' => 'int',
  194. 'not null' => TRUE,
  195. 'default' => 0,
  196. ),
  197. ),
  198. 'indexes' => array(
  199. 'vocab_id' => array('vocab_id'),
  200. 'term_id' => array('term_id'),
  201. 'entity_changed' => array('changed'),
  202. 'entity_created' => array('created'),
  203. ),
  204. 'foreign keys' => array(
  205. 'tripal_vocab' => array(
  206. 'table' => 'tripal_vocab',
  207. 'columns' => array(
  208. 'vocab_id' => 'vocab_id',
  209. ),
  210. ),
  211. ),
  212. 'unique keys' => array('vocab_term' => array('vocab_id', 'term_id')),
  213. 'primary key' => array('id'),
  214. );
  215. return $schema;
  216. }
  217. /**
  218. * The base table for TripalEntity entities.
  219. *
  220. * This table contains a list of Biological Data Types.
  221. * For the example above (5 genes and 10 mRNAs), there would only be two records in
  222. * this table one for "gene" and another for "mRNA".
  223. */
  224. function tripal_entities_tripal_bundle_schema() {
  225. $schema = array(
  226. 'description' => 'Stores information about defined tripal data types.',
  227. 'fields' => array(
  228. 'id' => array(
  229. 'type' => 'serial',
  230. 'not null' => TRUE,
  231. 'description' => 'Primary Key: Unique numeric ID.',
  232. ),
  233. 'type' => array(
  234. 'description' => 'The type of entity. This should be an official vocabulary ID (e.g. SO, RO, GO).',
  235. 'type' => 'varchar',
  236. 'length' => 64,
  237. 'not null' => TRUE,
  238. 'default' => '',
  239. ),
  240. 'bundle' => array(
  241. '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.',
  242. 'type' => 'varchar',
  243. 'length' => 1024,
  244. 'not null' => TRUE,
  245. 'default' => '',
  246. ),
  247. 'label' => array(
  248. 'description' => 'The human-readable name of this bundle.',
  249. 'type' => 'varchar',
  250. 'length' => 255,
  251. 'not null' => TRUE,
  252. 'default' => '',
  253. ),
  254. ),
  255. 'primary key' => array('id'),
  256. 'unique keys' => array(
  257. 'bundle' => array('bundle'),
  258. ),
  259. );
  260. return $schema;
  261. }