tripal_entities.install 11 KB

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