tripal_entities.install 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * @file
  4. * Install for a chado data entity - creates the base table for our entity.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. *
  9. * @ingroup entity_example
  10. */
  11. function tripal_entities_schema() {
  12. $schema['chado_data'] = array(
  13. 'description' => 'The base table for Tripal Vocabulary-based entities.',
  14. 'fields' => array(
  15. 'entity_id' => array(
  16. 'description' => 'The primary identifier for a vocabulary entity.',
  17. 'type' => 'serial',
  18. 'unsigned' => TRUE,
  19. 'not null' => TRUE,
  20. ),
  21. 'type' => array(
  22. 'description' => 'The type of entity. This should be an official term ID.',
  23. 'type' => 'varchar',
  24. 'length' => 64,
  25. 'not null' => TRUE,
  26. 'default' => '',
  27. ),
  28. 'cvterm_id' => array(
  29. 'description' => 'The cvterm_id for the type of entity. This cvterm_id should match a record in the Chado cvterm table.',
  30. 'type' => 'varchar',
  31. 'length' => 32,
  32. 'not null' => TRUE,
  33. 'default' => '',
  34. ),
  35. 'tablename' => array(
  36. 'description' => 'The Chado table that contains the record that this entity is associated with.',
  37. 'type' => 'varchar',
  38. 'length' => 128,
  39. 'not null' => TRUE,
  40. 'default' => ''
  41. ),
  42. 'record_id' => array(
  43. 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
  44. 'type' => 'int',
  45. 'not null' => TRUE,
  46. ),
  47. 'title' => array(
  48. 'description' => 'The title of this node, always treated as non-markup plain text.',
  49. 'type' => 'text',
  50. 'not null' => TRUE,
  51. 'default' => '',
  52. ),
  53. 'uid' => array(
  54. 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
  55. 'type' => 'int',
  56. 'not null' => TRUE,
  57. 'default' => 0,
  58. ),
  59. 'status' => array(
  60. 'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
  61. 'type' => 'int',
  62. 'not null' => TRUE,
  63. 'default' => 1,
  64. ),
  65. 'created' => array(
  66. 'description' => 'The Unix timestamp when the node was created.',
  67. 'type' => 'int',
  68. 'not null' => TRUE,
  69. 'default' => 0,
  70. ),
  71. 'changed' => array(
  72. 'description' => 'The Unix timestamp when the node was most recently saved.',
  73. 'type' => 'int',
  74. 'not null' => TRUE,
  75. 'default' => 0,
  76. ),
  77. ),
  78. 'indexes' => array(
  79. 'entity_changed' => array('changed'),
  80. 'entity_created' => array('created'),
  81. 'tablename' => array('tablename'),
  82. 'record_id' => array('record_id'),
  83. 'chado_record' => array('tablename', 'record_id'),
  84. 'type' => array('type'),
  85. 'cvterm_id' => array('cvterm_id'),
  86. 'uid' => array('uid'),
  87. ),
  88. 'unique keys' => array(
  89. 'record' => array('tablename', 'record_id'),
  90. ),
  91. 'primary key' => array('entity_id'),
  92. );
  93. $schema['chado_data_type'] = array(
  94. 'description' => 'Stores information about defined chado data types.',
  95. 'fields' => array(
  96. 'id' => array(
  97. 'type' => 'serial',
  98. 'not null' => TRUE,
  99. 'description' => 'Primary Key: Unique Chado data type identifier.',
  100. ),
  101. 'type' => array(
  102. 'description' => 'The machine-readable name of this chado data type.',
  103. 'type' => 'varchar',
  104. 'length' => 255,
  105. 'not null' => TRUE,
  106. ),
  107. 'label' => array(
  108. 'description' => 'The human-readable name of this chado data type.',
  109. 'type' => 'varchar',
  110. 'length' => 255,
  111. 'not null' => TRUE,
  112. 'default' => '',
  113. ),
  114. 'weight' => array(
  115. 'type' => 'int',
  116. 'not null' => TRUE,
  117. 'default' => 0,
  118. 'size' => 'tiny',
  119. 'description' => 'The weight of this chado data type in relation to others.',
  120. ),
  121. 'data' => array(
  122. 'type' => 'text',
  123. 'not null' => FALSE,
  124. 'size' => 'big',
  125. 'serialize' => TRUE,
  126. 'description' => 'A serialized array of additional data related to this chado data type.',
  127. ),
  128. ) + entity_exportable_schema_fields(),
  129. 'primary key' => array('id'),
  130. 'unique keys' => array(
  131. 'type' => array('type'),
  132. ),
  133. );
  134. return $schema;
  135. }
  136. /**
  137. * Implements hook_uninstall().
  138. *
  139. * At uninstall time we'll notify field.module that the entity was deleted
  140. * so that attached fields can be cleaned up.
  141. *
  142. * @ingroup entity_example
  143. */
  144. function tripal_entities_uninstall() {
  145. // TODO: make this dynamic (not hardcoded bundle).
  146. field_attach_delete_bundle('chado_data', 'gene');
  147. }