tripal_bulk_loader.install 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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' => 'int',
  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. 'created' => array(
  71. 'description' => 'The Unix timestamp when the template was created.',
  72. 'type' => 'int',
  73. 'not null' => TRUE,
  74. 'default' => 0,
  75. ),
  76. 'changed' => array(
  77. 'description' => 'The Unix timestamp when the template was most recently saved.',
  78. 'type' => 'int',
  79. 'not null' => TRUE,
  80. 'default' => 0,
  81. )
  82. ),
  83. 'primary key' => array('template_id'),
  84. 'unique keys' => array(
  85. 'name' => array('name')
  86. ),
  87. );
  88. $schema['tripal_bulk_loader_inserted'] = array(
  89. 'fields' => array(
  90. 'tripal_bulk_loader_inserted_id' => array(
  91. 'type' => 'serial',
  92. 'not null' => TRUE
  93. ),
  94. 'nid' => array(
  95. 'type' => 'int',
  96. 'unsigned' => TRUE,
  97. 'not null' => TRUE,
  98. ),
  99. 'table_inserted_into' => array(
  100. 'type' => 'varchar',
  101. 'not null' => TRUE,
  102. ),
  103. 'table_primary_key' => array(
  104. 'type' => 'varchar',
  105. 'not null' => TRUE,
  106. ),
  107. 'ids_inserted' => array(
  108. 'type' => 'text',
  109. 'not null' => TRUE
  110. ),
  111. ),
  112. 'primary key' => array('tripal_bulk_loader_inserted_id'),
  113. );
  114. $schema['tripal_bulk_loader_constants'] = array(
  115. 'fields' => array(
  116. 'constant_id' => array(
  117. 'type' => 'serial',
  118. 'not null' => TRUE
  119. ),
  120. 'nid' => array(
  121. 'type' => 'int',
  122. 'unsigned' => TRUE,
  123. 'not null' => TRUE,
  124. ),
  125. 'group_id' => array(
  126. 'type' => 'int',
  127. 'unsigned' => TRUE,
  128. 'not null' => TRUE,
  129. 'default' => 0
  130. ),
  131. 'chado_table' => array(
  132. 'type' => 'varchar',
  133. 'not null' => TRUE,
  134. ),
  135. 'chado_field' => array(
  136. 'type' => 'varchar',
  137. 'not null' => TRUE,
  138. ),
  139. 'record_id' => array(
  140. 'type' => 'int',
  141. 'not null' => TRUE
  142. ),
  143. 'field_id' => array(
  144. 'type' => 'int',
  145. 'not null' => TRUE
  146. ),
  147. 'value' => array(
  148. 'type' => 'text',
  149. ),
  150. ),
  151. 'primary key' => array('constant_id'),
  152. );
  153. return $schema;
  154. }
  155. /**
  156. * Update schema for version 6.x-0.3.1b-1.5
  157. * - Add the tripal_bulk_loader_constants table
  158. */
  159. function tripal_bulk_loader_update_6150() {
  160. // Create tripal_bulk_loader_constants table
  161. $schema = tripal_bulk_loader_schema();
  162. db_create_table('tripal_bulk_loader_constants', $schema['tripal_bulk_loader_constants']);
  163. return 'Added support for loader-specific constants.';
  164. }
  165. /**
  166. * Update schema for version 6.x-0.3.1b-1.5
  167. * - Add the tripal_bulk_loader_constants.group_id column
  168. * to allow multiple sets of constants per job
  169. */
  170. function tripal_bulk_loader_update_6151() {
  171. $schema = tripal_bulk_loader_schema();
  172. db_add_field(
  173. 'tripal_bulk_loader_constants',
  174. 'group_id',
  175. array(
  176. 'type' => 'int',
  177. 'unsigned' => TRUE,
  178. 'not null' => TRUE,
  179. 'default' => 0
  180. )
  181. );
  182. return 'Added support for multiple sets of loader-specific constants.';
  183. }
  184. function tripal_bulk_loader_update_6152() {
  185. db_add_field(
  186. 'tripal_bulk_loader',
  187. 'keep_track_inserted',
  188. array(
  189. 'type' => 'int',
  190. 'size' => 'tiny',
  191. 'not null' => TRUE,
  192. 'default' => 1
  193. )
  194. );
  195. return 'Added ability to rollback loading job based on storing loaded ids.';
  196. }
  197. /**
  198. * Update to 7.x-2.0
  199. * -Cast tripal_bulk_loader.template_id to int field
  200. */
  201. function tripal_bulk_loader_update_7201() {
  202. db_change_field(
  203. 'tripal_bulk_loader',
  204. 'template_id',
  205. 'template_id',
  206. array('type' => 'int')
  207. );
  208. db_add_field(
  209. 'tripal_bulk_loader_template',
  210. 'created',
  211. array(
  212. 'description' => 'The Unix timestamp when the template was created.',
  213. 'type' => 'int',
  214. 'not null' => TRUE,
  215. 'default' => 0,
  216. )
  217. );
  218. db_add_field(
  219. 'tripal_bulk_loader_template',
  220. 'changed',
  221. array(
  222. 'description' => 'The Unix timestamp when the template was most recently saved.',
  223. 'type' => 'int',
  224. 'not null' => TRUE,
  225. 'default' => 0,
  226. )
  227. );
  228. return 'Updated tripal_bulk_loader.template_id from character to integer '
  229. . 'and added time created/updated track to templates.';
  230. }
  231. /**
  232. * Implementation of hook_requirements().
  233. */
  234. function tripal_bulk_loader_requirements($phase) {
  235. $requirements = array();
  236. if ($phase == 'install') {
  237. // make sure chado is installed
  238. if (!tripal_core_is_chado_installed()) {
  239. $requirements ['tripal_bulk_loader'] = array(
  240. 'title' => "tripal_bulk_loader",
  241. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  242. 'severity' => REQUIREMENT_ERROR,
  243. );
  244. }
  245. }
  246. return $requirements;
  247. }