tripal_core.install 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. /************************************************************************
  3. * Implementation of hook_install();
  4. *
  5. * @ingroup tripal_core
  6. */
  7. function tripal_core_install(){
  8. // make the data directory for this module
  9. $data_dir = file_directory_path() . "/tripal";
  10. if(!file_check_directory($data_dir,FILE_CREATE_DIRECTORY)){
  11. $message = "Cannot create directory $data_dir. This module may not ".
  12. "behave correctly without this directory. Please create ".
  13. "the directory manually or fix the problem and reinstall.";
  14. drupal_set_message($message,'error');
  15. watchdog('tripal_core',$message,array(),WATCHDOG_ERROR);
  16. }
  17. // create the tables that manage materialized views and jobs
  18. drupal_install_schema('tripal_core');
  19. }
  20. /************************************************************************
  21. * Implementation of hook_schema().
  22. *
  23. * @ingroup tripal_core
  24. */
  25. function tripal_core_schema() {
  26. $schema = tripal_core_get_schemas();
  27. return $schema;
  28. }
  29. /************************************************************************
  30. * Implementation of hook_uninstall()
  31. *
  32. * @ingroup tripal_core
  33. */
  34. function tripal_core_uninstall(){
  35. drupal_uninstall_schema('tripal_core');
  36. }
  37. /************************************************************************
  38. * This function simply defines all tables needed for the module to work
  39. * correctly. By putting the table definitions in a separate function we
  40. * can easily provide the entire list for hook_install or individual
  41. * tables for an update.
  42. *
  43. * @ingroup tripal_core
  44. */
  45. function tripal_core_get_schemas (){
  46. $schema = array();
  47. $schema['tripal_jobs'] = array(
  48. 'fields' => array(
  49. 'job_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  50. 'uid' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The Drupal userid of the submitee'),
  51. 'job_name' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  52. 'modulename' => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  53. 'callback' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  54. 'arguments' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
  55. 'progress' => array('type' => 'int', 'unsigned' => TRUE, 'default' => 0, 'not null' => FALSE, 'description' => 'a value from 0 to 100 indicating percent complete'),
  56. 'status' => array('type' => 'varchar','length' => 50, 'not null' => TRUE),
  57. 'submit_date' => array ('type' => 'int', 'not null' => TRUE, 'description' => 'UNIX integer submit time'),
  58. 'start_time' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer start time'),
  59. 'end_time' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer end time'),
  60. 'error_msg' => array('type' => 'text','size' => 'normal', 'not null' => FALSE),
  61. 'pid' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'The process id for the job'),
  62. 'priority' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => '0', 'description' => 'The job priority'),
  63. 'mlock' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'If set to 1 then all jobs for the module are held until this one finishes'),
  64. 'lock' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'If set to 1 then all jobs are held until this one finishes'),
  65. ),
  66. 'indexes' => array(
  67. 'job_id' => array('job_id'),
  68. 'job_name' => array('job_name')
  69. ),
  70. 'primary key' => array('job_id'),
  71. );
  72. $schema['tripal_mviews'] = array(
  73. 'fields' => array(
  74. 'mview_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  75. 'name' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  76. 'modulename' => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  77. 'mv_table' => array('type' => 'varchar','length' => 128, 'not null' => TRUE),
  78. 'mv_specs' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  79. 'indexed' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  80. 'query' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  81. 'special_index' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
  82. 'last_update' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer time'),
  83. ),
  84. 'indexes' => array(
  85. 'mview_id' => array('mview_id')
  86. ),
  87. 'unique keys' => array(
  88. 'mv_table' => array('mv_table'),
  89. 'mv_name' => array('name'),
  90. ),
  91. 'primary key' => array('mview_id'),
  92. );
  93. $schema = tripal_core_views_integration_schema();
  94. return $schema;
  95. }
  96. /************************************************************************
  97. *
  98. *
  99. * @ingroup tripal_core
  100. */
  101. function tripal_core_views_integration_schema(){
  102. $schema['tripal_views_integration'] = array(
  103. 'description' => 'contains the setupes, their materialized view id and base table name that was used.',
  104. 'fields' => array(
  105. 'setup_id' => array(
  106. 'description' => 'the id of the setup',
  107. 'type' => 'serial',
  108. 'unsigned' => TRUE,
  109. 'not null' => TRUE,
  110. ),
  111. 'mview_id' => array(
  112. 'description' => 'the materialized view used for this setup',
  113. 'type' => 'int',
  114. 'unsigned' => TRUE,
  115. ),
  116. 'chado_table_name' => array(
  117. 'description' => 'the base table name to be used when using this setup',
  118. 'type' => 'varchar',
  119. 'length' => 255,
  120. 'not null' => TRUE,
  121. 'default' => '',
  122. ),
  123. 'name' => array(
  124. 'description' => 'Human readable name of this setup',
  125. 'type' => 'varchar',
  126. 'length' => 255,
  127. 'not null' => TRUE,
  128. 'default' => '',
  129. ),
  130. 'description' => array(
  131. 'description' => 'description of this row',
  132. 'type' => 'varchar',
  133. 'length' => 255,
  134. 'not null' => TRUE,
  135. 'default' => '',
  136. ),
  137. ),
  138. 'unique_keys' => array(
  139. 'setup_id' => array('setup_id'),
  140. ),
  141. 'primary key' => array('setup_id'),
  142. );
  143. $schema['tripal_mviews_join'] = array(
  144. 'description' => 'which materialzed views and chado tables to join in a given setup',
  145. 'fields' => array(
  146. 'mview_join_id' => array(
  147. 'description' => 'the id of the join',
  148. 'type' => 'serial',
  149. 'unsigned' => TRUE,
  150. 'not null' => TRUE,
  151. ),
  152. 'setup_id' => array(
  153. 'description' => 'tripal setup id from tripal_views_integration table',
  154. 'type' => 'int',
  155. 'unsigned' => TRUE,
  156. 'not null'=> TRUE,
  157. ),
  158. 'view_table' => array(
  159. 'description' => 'materialized view table name',
  160. 'type' => 'varchar',
  161. 'length' => '255',
  162. 'not null' => TRUE,
  163. 'default' => '',
  164. ),
  165. 'view_column' => array(
  166. 'description' => 'column of materialized view table (mview_table)',
  167. 'type' => 'varchar',
  168. 'length' => '255',
  169. 'not null' => TRUE,
  170. 'default' => '',
  171. ),
  172. 'chado_table_join' => array(
  173. 'description' => 'on which chado table to join to materialized view in this serach',
  174. 'type' => 'varchar',
  175. 'length' => '255',
  176. 'not null' => TRUE,
  177. 'default' => '',
  178. ),
  179. 'chado_column' => array(
  180. 'description' => 'chado table (above) column to join on materialized view in this serach',
  181. 'type' => 'varchar',
  182. 'length' => '255',
  183. 'not null' => TRUE,
  184. 'default' => '',
  185. ),
  186. ),
  187. 'unique_keys' => array(
  188. 'setup_id' => array('mview_join_id'),
  189. ),
  190. 'primary key' => array('mview_join_id'),
  191. );
  192. $schema['tripal_views_handlers'] = array(
  193. 'description' => 'in formation for views: column and views handler name',
  194. 'fields' => array(
  195. 'handler_id' => array(
  196. 'description' => 'the id of the handler',
  197. 'type' => 'serial',
  198. 'unsigned' => TRUE,
  199. 'not null' => TRUE,
  200. ),
  201. 'setup_id' => array(
  202. 'description' => 'which setup this is used by from tripal_views_integration table',
  203. 'type' => 'int',
  204. 'unsigned' => TRUE,
  205. 'not null'=> TRUE,
  206. ),
  207. 'column_name' => array(
  208. 'description' => '',
  209. 'type' => 'varchar',
  210. 'length' => '255',
  211. 'not null' => TRUE,
  212. 'default' => '',
  213. ),
  214. 'handler_filter' => array(
  215. 'description' => 'identifier of the handler filter to be used for this column',
  216. 'type' => 'varchar',
  217. 'length' => '255',
  218. 'not null' => TRUE,
  219. 'default' => '',
  220. ),
  221. 'handler_field' => array(
  222. 'description' => 'identifier of the handler field to be used for this column',
  223. 'type' => 'varchar',
  224. 'length' => '255',
  225. 'not null' => TRUE,
  226. 'default' => '',
  227. ),
  228. ),
  229. 'unique_keys' => array(
  230. 'setup_id' => array('handler_id'),
  231. ),
  232. 'primary key' => array('handler_id'),
  233. );
  234. return $schema;
  235. }
  236. /************************************************************************
  237. *
  238. *
  239. * @ingroup tripal_core
  240. */
  241. function tripal_core_update_6000(){
  242. // recreate the materialized view
  243. tripal_feature_add_organism_count_mview();
  244. $ret = array(
  245. '#finished' => 1,
  246. );
  247. return $ret;
  248. }
  249. /************************************************************************
  250. *
  251. *
  252. * @ingroup tripal_core
  253. */
  254. function tripal_core_update_6000_views_integration(){
  255. }
  256. ?>