tripal_bulk_loader.install 4.4 KB

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