tripal_bulk_loader.install 4.2 KB

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