tripal_views.install 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. return $ret;
  61. }
  62. /************************************************************************
  63. *
  64. *
  65. * @ingroup tripal_views
  66. */
  67. function tripal_views_views_schema(){
  68. $schema = array();
  69. $schema['tripal_views'] = array(
  70. 'description' => 'contains the setupes, their materialized view id and base table name that was used.',
  71. 'fields' => array(
  72. 'setup_id' => array(
  73. 'description' => 'the id of the setup',
  74. 'type' => 'serial',
  75. 'unsigned' => TRUE,
  76. 'not null' => TRUE,
  77. ),
  78. 'mview_id' => array(
  79. 'description' => 'the materialized view used for this setup',
  80. 'type' => 'int',
  81. 'unsigned' => TRUE,
  82. ),
  83. 'table_name' => array(
  84. 'description' => 'the base table name to be used when using this setup. Use this field when not using a materialized view',
  85. 'type' => 'varchar',
  86. 'length' => 255,
  87. 'not null' => TRUE,
  88. 'default' => '',
  89. ),
  90. 'priority' => array(
  91. 'description' => 'when there are 2+ entries for the same table, the entry with the lightest (drupal-style) priority is used.',
  92. 'type' => 'int',
  93. ),
  94. 'name' => array(
  95. 'description' => 'Human readable name of this setup',
  96. 'type' => 'varchar',
  97. 'length' => 255,
  98. 'not null' => TRUE,
  99. 'default' => '',
  100. ),
  101. 'comment' => array(
  102. 'description' => 'add notes about this views setup',
  103. 'type' => 'text',
  104. 'size' => 'normal',
  105. 'not null' => FALSE,
  106. 'default' => '',
  107. ),
  108. ),
  109. 'unique_keys' => array(
  110. 'setup_id' => array('setup_id'),
  111. 'priority' => array('table_name','priority'),
  112. ),
  113. 'indexes' => array(
  114. 'priority' => array('table_name','priority'),
  115. ),
  116. 'primary key' => array('setup_id'),
  117. );
  118. $schema['tripal_views_field'] = array(
  119. 'description' => 'keep track of fields available for a given table',
  120. 'fields' => array(
  121. 'setup_id' => array(
  122. 'description' => 'the id of the setup',
  123. 'type' => 'int',
  124. 'unsigned' => TRUE,
  125. 'not null' => TRUE,
  126. ),
  127. 'column_name' => array(
  128. 'description' => 'the name of the field in the database',
  129. 'type' => 'varchar',
  130. 'length' => '255',
  131. 'not null' => TRUE,
  132. ),
  133. 'name' => array(
  134. 'description' => 'the human-readable name of the field',
  135. 'type' => 'varchar',
  136. 'length' => '255',
  137. 'not null' => TRUE,
  138. ),
  139. 'description' => array(
  140. 'description' => 'A short description of the field -seen under the field in the views UI',
  141. 'type' => 'varchar',
  142. 'length' => '255',
  143. 'not null' => TRUE,
  144. ),
  145. 'type' => array(
  146. 'description' => 'the database type of this field (ie: int, varchar)',
  147. 'type' => 'varchar',
  148. 'length' => '50',
  149. 'not null' => TRUE,
  150. ),
  151. ),
  152. 'primary key' => array('setup_id','column_name')
  153. );
  154. $schema['tripal_views_join'] = array(
  155. 'description' => 'coordinate the joining of tables',
  156. 'fields' => array(
  157. 'view_join_id' => array(
  158. 'description' => 'the id of the join',
  159. 'type' => 'serial',
  160. 'unsigned' => TRUE,
  161. 'not null' => TRUE,
  162. ),
  163. 'setup_id' => array(
  164. 'description' => 'setup id from tripal_views table',
  165. 'type' => 'int',
  166. 'unsigned' => TRUE,
  167. 'not null'=> TRUE,
  168. ),
  169. 'base_table' => array(
  170. 'description' => 'the name of the base table',
  171. 'type' => 'varchar',
  172. 'length' => '255',
  173. 'not null' => TRUE,
  174. 'default' => '',
  175. ),
  176. 'base_field' => array(
  177. 'description' => 'the name of the base table column that will be joined',
  178. 'type' => 'varchar',
  179. 'length' => '255',
  180. 'not null' => TRUE,
  181. 'default' => '',
  182. ),
  183. 'left_table' => array(
  184. 'description' => 'the table on which to perform a left join',
  185. 'type' => 'varchar',
  186. 'length' => '255',
  187. 'not null' => TRUE,
  188. 'default' => '',
  189. ),
  190. 'left_field' => array(
  191. 'description' => 'the column on which to perform a left join',
  192. 'type' => 'varchar',
  193. 'length' => '255',
  194. 'not null' => TRUE,
  195. 'default' => '',
  196. ),
  197. 'handler' => array(
  198. 'description' => 'the name of the handler',
  199. 'type' => 'varchar',
  200. 'length' => '255',
  201. 'not null' => TRUE,
  202. 'default' => '',
  203. ),
  204. ),
  205. 'unique_keys' => array(
  206. 'setup_id' => array('view_join_id'),
  207. ),
  208. 'primary key' => array('view_join_id'),
  209. );
  210. $schema['tripal_views_handlers'] = array(
  211. 'description' => 'in formation for views: column and views handler name',
  212. 'fields' => array(
  213. 'handler_id' => array(
  214. 'description' => 'the id of the handler',
  215. 'type' => 'serial',
  216. 'unsigned' => TRUE,
  217. 'not null' => TRUE,
  218. ),
  219. 'setup_id' => array(
  220. 'description' => 'setup id from the tripal_views table',
  221. 'type' => 'int',
  222. 'unsigned' => TRUE,
  223. 'not null'=> TRUE,
  224. ),
  225. 'column_name' => array(
  226. 'description' => '',
  227. 'type' => 'varchar',
  228. 'length' => '255',
  229. 'not null' => TRUE,
  230. 'default' => '',
  231. ),
  232. 'handler_type' => array(
  233. 'description' => 'identifies the type of hander (e.g. field, filter, sort, argument, relationship, etc.)',
  234. 'type' => 'varchar',
  235. 'length' => '50',
  236. 'not null' => TRUE,
  237. 'default' => '',
  238. ),
  239. 'handler_name' => array(
  240. 'description' => 'the name of the handler',
  241. 'type' => 'varchar',
  242. 'length' => '255',
  243. 'not null' => TRUE,
  244. 'default' => '',
  245. ),
  246. 'arguments' => array(
  247. 'description' => 'arguments that may get passed to the handler',
  248. 'type' => 'text',
  249. 'size' => 'normal',
  250. 'not null' => FALSE,
  251. 'default' => '',
  252. ),
  253. ),
  254. 'unique_keys' => array(
  255. 'setup_id' => array('handler_id'),
  256. ),
  257. 'primary key' => array('handler_id'),
  258. );
  259. return $schema;
  260. }
  261. ?>