tripal_bulk_loader.install 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * Implements hook_schema
  8. *
  9. * Creates the following tables in the Drupal database:
  10. * - tripal_bulk_loader: Stores extra details for bulk loading jobs (nodes)
  11. * - tripal_bulk_loader_template: Stores all loading templates
  12. * - tripal_bulk_loader_inserted: Keeps track of all records inserted for a given bulk loading job
  13. */
  14. function tripal_bulk_loader_schema() {
  15. $schema = array();
  16. $schema['tripal_bulk_loader'] = array(
  17. 'fields' => array(
  18. 'nid' => array(
  19. 'type' => 'int',
  20. 'unsigned' => TRUE,
  21. 'not null' => TRUE,
  22. ),
  23. 'loader_name' => array(
  24. 'type' => 'varchar',
  25. ),
  26. 'template_id' => array(
  27. 'type' => 'varchar',
  28. ),
  29. 'file' => array(
  30. 'type' => 'varchar',
  31. 'not null' => TRUE
  32. ),
  33. 'job_id' => array(
  34. 'type' => 'int',
  35. ),
  36. 'job_status' => array(
  37. 'type' => 'varchar',
  38. ),
  39. 'file_has_header' => array(
  40. 'type' => 'int',
  41. 'size' => 'tiny',
  42. 'not null' => TRUE,
  43. 'default' => 0,
  44. ),
  45. 'keep_track_inserted' => array(
  46. 'type' => 'int',
  47. 'size' => 'tiny',
  48. 'not null' => TRUE,
  49. 'default' => 1
  50. ),
  51. ),
  52. 'primary key' => array('nid'),
  53. 'unique keys' => array(
  54. 'name' => array('loader_name')
  55. ),
  56. );
  57. $schema['tripal_bulk_loader_template'] = array(
  58. 'fields' => array(
  59. 'template_id' => array(
  60. 'type' => 'serial',
  61. 'unsigned' => TRUE,
  62. 'not null' => TRUE,
  63. ),
  64. 'name' => array(
  65. 'type' => 'varchar',
  66. ),
  67. 'template_array' => array(
  68. 'type' => 'varchar',
  69. )
  70. ),
  71. 'primary key' => array('template_id'),
  72. 'unique keys' => array(
  73. 'name' => array('name')
  74. ),
  75. );
  76. $schema['tripal_bulk_loader_inserted'] = array(
  77. 'fields' => array(
  78. 'tripal_bulk_loader_inserted_id' => array(
  79. 'type' => 'serial',
  80. 'not null' => TRUE
  81. ),
  82. 'nid' => array(
  83. 'type' => 'int',
  84. 'unsigned' => TRUE,
  85. 'not null' => TRUE,
  86. ),
  87. 'table_inserted_into' => array(
  88. 'type' => 'varchar',
  89. 'not null' => TRUE,
  90. ),
  91. 'table_primary_key' => array(
  92. 'type' => 'varchar',
  93. 'not null' => TRUE,
  94. ),
  95. 'ids_inserted' => array(
  96. 'type' => 'text',
  97. 'not null' => TRUE
  98. ),
  99. ),
  100. 'primary key' => array('tripal_bulk_loader_inserted_id'),
  101. );
  102. $schema['tripal_bulk_loader_constants'] = array(
  103. 'fields' => array(
  104. 'constant_id' => array(
  105. 'type' => 'serial',
  106. 'not null' => TRUE
  107. ),
  108. 'nid' => array(
  109. 'type' => 'int',
  110. 'unsigned' => TRUE,
  111. 'not null' => TRUE,
  112. ),
  113. 'group_id' => array(
  114. 'type' => 'int',
  115. 'unsigned' => TRUE,
  116. 'not null' => TRUE,
  117. 'default' => 0
  118. ),
  119. 'chado_table' => array(
  120. 'type' => 'varchar',
  121. 'not null' => TRUE,
  122. ),
  123. 'chado_field' => array(
  124. 'type' => 'varchar',
  125. 'not null' => TRUE,
  126. ),
  127. 'record_id' => array(
  128. 'type' => 'int',
  129. 'not null' => TRUE
  130. ),
  131. 'field_id' => array(
  132. 'type' => 'int',
  133. 'not null' => TRUE
  134. ),
  135. 'value' => array(
  136. 'type' => 'text',
  137. ),
  138. ),
  139. 'primary key' => array('constant_id'),
  140. );
  141. return $schema;
  142. }
  143. /**
  144. * Update schema for version 6.x-0.3.1b-1.5
  145. * - Add the tripal_bulk_loader_constants table
  146. */
  147. function tripal_bulk_loader_update_6150() {
  148. // Create tripal_bulk_loader_constants table
  149. $schema = tripal_bulk_loader_schema();
  150. db_create_table('tripal_bulk_loader_constants', $schema['tripal_bulk_loader_constants']);
  151. return 'Added support for loader-specific constants.';
  152. }
  153. /**
  154. * Update schema for version 6.x-0.3.1b-1.5
  155. * - Add the tripal_bulk_loader_constants.group_id column
  156. * to allow multiple sets of constants per job
  157. */
  158. function tripal_bulk_loader_update_6151() {
  159. $schema = tripal_bulk_loader_schema();
  160. db_add_field(
  161. 'tripal_bulk_loader_constants',
  162. 'group_id',
  163. array(
  164. 'type' => 'int',
  165. 'unsigned' => TRUE,
  166. 'not null' => TRUE,
  167. 'default' => 0
  168. )
  169. );
  170. return 'Added support for multiple sets of loader-specific constants.';
  171. }
  172. function tripal_bulk_loader_update_6152() {
  173. db_add_field(
  174. 'tripal_bulk_loader',
  175. 'keep_track_inserted',
  176. array(
  177. 'type' => 'int',
  178. 'size' => 'tiny',
  179. 'not null' => TRUE,
  180. 'default' => 1
  181. )
  182. );
  183. return 'Added ability to rollback loading job based on storing loaded ids.';
  184. }
  185. /**
  186. * Implementation of hook_requirements().
  187. */
  188. function tripal_bulk_loader_requirements($phase) {
  189. $requirements = array();
  190. if ($phase == 'install') {
  191. // make sure chado is installed
  192. if (!tripal_core_is_chado_installed()) {
  193. $requirements ['tripal_bulk_loader'] = array(
  194. 'title' => "tripal_bulk_loader",
  195. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  196. 'severity' => REQUIREMENT_ERROR,
  197. );
  198. }
  199. }
  200. return $requirements;
  201. }