tripal_views.install 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. /************************************************************************
  3. * Implementation of hook_install();
  4. *
  5. * @ingroup tripal_views
  6. */
  7. function tripal_views_install(){
  8. // create the module's data directory
  9. tripal_create_moddir('tripal_views');
  10. // create the tables that manage materialized views and jobs
  11. drupal_install_schema('tripal_views');
  12. }
  13. /************************************************************************
  14. * Implementation of hook_schema().
  15. *
  16. * @ingroup tripal_views
  17. */
  18. function tripal_views_schema() {
  19. $schema = tripal_views_get_schemas();
  20. return $schema;
  21. }
  22. /************************************************************************
  23. * Implementation of hook_uninstall()
  24. *
  25. * @ingroup tripal_views
  26. */
  27. function tripal_views_uninstall(){
  28. drupal_uninstall_schema('tripal_views');
  29. }
  30. /************************************************************************
  31. * This function simply defines all tables needed for the module to work
  32. * correctly. By putting the table definitions in a separate function we
  33. * can easily provide the entire list for hook_install or individual
  34. * tables for an update.
  35. *
  36. * @ingroup tripal_views
  37. */
  38. function tripal_views_get_schemas (){
  39. $schema = array();
  40. $temp = tripal_views_views_schema();
  41. foreach ($temp as $table => $arr){
  42. $schema[$table] = $arr;
  43. }
  44. return $schema;
  45. }
  46. /**
  47. *
  48. */
  49. function tripal_views_update_6040 () {
  50. $ret = array();
  51. // Add Priority to tripal_views
  52. db_add_field($ret, 'tripal_views', 'priority', array('type' => 'int'));
  53. db_add_unique_key($ret,'tripal_views', 'priority', array('table_name','priority'));
  54. db_add_index($ret,'tripal_views', 'priority', array('table_name','priority'));
  55. // Add handler to tripal_views_join
  56. db_add_field($ret, 'tripal_views_join', 'handler', array('type' => 'varchar','length' => '255','not null' => TRUE,'default' => ''));
  57. // Add tripal_views_field to keep track of fields for views integration
  58. $schema = tripal_views_views_schema();
  59. db_create_table(&$ret, 'tripal_views_field', $schema['tripal_views_field']);
  60. // Add base_table TRUE/FALSE to tripal_views
  61. db_add_field($ret, 'tripal_views', 'base_table', array('type' => 'int', 'not null ' => TRUE,
  62. 'default' => 1));
  63. return $ret;
  64. }
  65. /************************************************************************
  66. *
  67. *
  68. * @ingroup tripal_views
  69. */
  70. function tripal_views_views_schema(){
  71. $schema = array();
  72. $schema['tripal_views'] = array(
  73. 'description' => 'contains the setupes, their materialized view id and base table name that was used.',
  74. 'fields' => array(
  75. 'setup_id' => array(
  76. 'description' => 'the id of the setup',
  77. 'type' => 'serial',
  78. 'unsigned' => TRUE,
  79. 'not null' => TRUE,
  80. ),
  81. 'mview_id' => array(
  82. 'description' => 'the materialized view used for this setup',
  83. 'type' => 'int',
  84. 'unsigned' => TRUE,
  85. ),
  86. 'table_name' => array(
  87. 'description' => 'the base table name to be used when using this setup. Use this field when not using a materialized view',
  88. 'type' => 'varchar',
  89. 'length' => 255,
  90. 'not null' => TRUE,
  91. 'default' => '',
  92. ),
  93. 'priority' => array(
  94. 'description' => 'when there are 2+ entries for the same table, the entry with the lightest (drupal-style) priority is used.',
  95. 'type' => 'int',
  96. ),
  97. 'name' => array(
  98. 'description' => 'Human readable name of this setup',
  99. 'type' => 'varchar',
  100. 'length' => 255,
  101. 'not null' => TRUE,
  102. 'default' => '',
  103. ),
  104. 'base_table' => array(
  105. 'description' => 'Indicated whether the table should be a base table of a view',
  106. 'type' => 'int',
  107. 'not null ' => TRUE,
  108. 'default' => 1
  109. ),
  110. 'comment' => array(
  111. 'description' => 'add notes about this views setup',
  112. 'type' => 'text',
  113. 'size' => 'normal',
  114. 'not null' => FALSE,
  115. 'default' => '',
  116. ),
  117. ),
  118. 'unique_keys' => array(
  119. 'setup_id' => array('setup_id'),
  120. 'priority' => array('table_name','priority'),
  121. ),
  122. 'indexes' => array(
  123. 'priority' => array('table_name','priority'),
  124. ),
  125. 'primary key' => array('setup_id'),
  126. );
  127. $schema['tripal_views_field'] = array(
  128. 'description' => 'keep track of fields available for a given table',
  129. 'fields' => array(
  130. 'setup_id' => array(
  131. 'description' => 'the id of the setup',
  132. 'type' => 'int',
  133. 'unsigned' => TRUE,
  134. 'not null' => TRUE,
  135. ),
  136. 'column_name' => array(
  137. 'description' => 'the name of the field in the database',
  138. 'type' => 'varchar',
  139. 'length' => '255',
  140. 'not null' => TRUE,
  141. ),
  142. 'name' => array(
  143. 'description' => 'the human-readable name of the field',
  144. 'type' => 'varchar',
  145. 'length' => '255',
  146. 'not null' => TRUE,
  147. ),
  148. 'description' => array(
  149. 'description' => 'A short description of the field -seen under the field in the views UI',
  150. 'type' => 'varchar',
  151. 'length' => '255',
  152. 'not null' => TRUE,
  153. ),
  154. 'type' => array(
  155. 'description' => 'the database type of this field (ie: int, varchar)',
  156. 'type' => 'varchar',
  157. 'length' => '50',
  158. 'not null' => TRUE,
  159. ),
  160. ),
  161. 'primary key' => array('setup_id','column_name')
  162. );
  163. $schema['tripal_views_join'] = array(
  164. 'description' => 'coordinate the joining of tables',
  165. 'fields' => array(
  166. 'view_join_id' => array(
  167. 'description' => 'the id of the join',
  168. 'type' => 'serial',
  169. 'unsigned' => TRUE,
  170. 'not null' => TRUE,
  171. ),
  172. 'setup_id' => array(
  173. 'description' => 'setup id from tripal_views table',
  174. 'type' => 'int',
  175. 'unsigned' => TRUE,
  176. 'not null'=> TRUE,
  177. ),
  178. 'base_table' => array(
  179. 'description' => 'the name of the base table',
  180. 'type' => 'varchar',
  181. 'length' => '255',
  182. 'not null' => TRUE,
  183. 'default' => '',
  184. ),
  185. 'base_field' => array(
  186. 'description' => 'the name of the base table column that will be joined',
  187. 'type' => 'varchar',
  188. 'length' => '255',
  189. 'not null' => TRUE,
  190. 'default' => '',
  191. ),
  192. 'left_table' => array(
  193. 'description' => 'the table on which to perform a left join',
  194. 'type' => 'varchar',
  195. 'length' => '255',
  196. 'not null' => TRUE,
  197. 'default' => '',
  198. ),
  199. 'left_field' => array(
  200. 'description' => 'the column on which to perform a left join',
  201. 'type' => 'varchar',
  202. 'length' => '255',
  203. 'not null' => TRUE,
  204. 'default' => '',
  205. ),
  206. 'handler' => array(
  207. 'description' => 'the name of the handler',
  208. 'type' => 'varchar',
  209. 'length' => '255',
  210. 'not null' => TRUE,
  211. 'default' => '',
  212. ),
  213. ),
  214. 'unique_keys' => array(
  215. 'setup_id' => array('view_join_id'),
  216. ),
  217. 'primary key' => array('view_join_id'),
  218. );
  219. $schema['tripal_views_handlers'] = array(
  220. 'description' => 'in formation for views: column and views handler name',
  221. 'fields' => array(
  222. 'handler_id' => array(
  223. 'description' => 'the id of the handler',
  224. 'type' => 'serial',
  225. 'unsigned' => TRUE,
  226. 'not null' => TRUE,
  227. ),
  228. 'setup_id' => array(
  229. 'description' => 'setup id from the tripal_views table',
  230. 'type' => 'int',
  231. 'unsigned' => TRUE,
  232. 'not null'=> TRUE,
  233. ),
  234. 'column_name' => array(
  235. 'description' => '',
  236. 'type' => 'varchar',
  237. 'length' => '255',
  238. 'not null' => TRUE,
  239. 'default' => '',
  240. ),
  241. 'handler_type' => array(
  242. 'description' => 'identifies the type of hander (e.g. field, filter, sort, argument, relationship, etc.)',
  243. 'type' => 'varchar',
  244. 'length' => '50',
  245. 'not null' => TRUE,
  246. 'default' => '',
  247. ),
  248. 'handler_name' => array(
  249. 'description' => 'the name of the handler',
  250. 'type' => 'varchar',
  251. 'length' => '255',
  252. 'not null' => TRUE,
  253. 'default' => '',
  254. ),
  255. 'arguments' => array(
  256. 'description' => 'arguments that may get passed to the handler',
  257. 'type' => 'text',
  258. 'size' => 'normal',
  259. 'not null' => FALSE,
  260. 'default' => '',
  261. ),
  262. ),
  263. 'unique_keys' => array(
  264. 'setup_id' => array('handler_id'),
  265. ),
  266. 'primary key' => array('handler_id'),
  267. );
  268. return $schema;
  269. }
  270. ?>