You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
10 KiB

  1. DO $$
  2. DECLARE
  3. --id fields
  4. idfieldsituationcode bigint;
  5. idfieldslatitude bigint;
  6. idfieldslongitude bigint;
  7. idfieldsaddress bigint;
  8. idfieldsdate bigint;
  9. idfieldstime bigint;
  10. idfieldscomment bigint;
  11. idfieldsimages bigint;
  12. idfieldsinsname bigint;
  13. idfieldsinstype bigint;
  14. idfieldsvalue bigint;
  15. --id forms
  16. idfloodzonesform bigint;
  17. idrainform bigint;
  18. idriverform bigint;
  19. idpluvform bigint;
  20. idpluvregsform bigint;
  21. BEGIN
  22. ---------------------------------- Fields --------------------------------------------------
  23. --situação do evento
  24. INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
  25. SELECT fdt.id, 'Situation', 'situation of the event', '', 1
  26. FROM fieldsdatatypes fdt
  27. WHERE fdt.name = 'text'
  28. RETURNING id INTO idfieldsituationcode;
  29. --Latitude
  30. INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
  31. SELECT fdt.id, 'Latitude', 'Event location latitude', '', 1
  32. FROM fieldsdatatypes fdt
  33. WHERE fdt.name = 'real'
  34. RETURNING id INTO idfieldslatitude;
  35. --Longitude
  36. INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
  37. SELECT fdt.id, 'Longitude', 'Event location longitude', '', 1
  38. FROM fieldsdatatypes fdt
  39. WHERE fdt.name = 'real'
  40. RETURNING id INTO idfieldslongitude;
  41. --Endereço
  42. INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
  43. SELECT fdt.id, 'Address', 'Event adress', '', 1
  44. FROM fieldsdatatypes fdt
  45. WHERE fdt.name = 'text'
  46. RETURNING id INTO idfieldsaddress;
  47. --Data
  48. INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
  49. SELECT fdt.id, 'Date_event', 'Event date', '', 1
  50. FROM fieldsdatatypes fdt
  51. WHERE fdt.name = 'text'
  52. RETURNING id INTO idfieldsdate;
  53. --Hora
  54. INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
  55. SELECT fdt.id, 'Time_event', 'Event time', '', 1
  56. FROM fieldsdatatypes fdt
  57. WHERE fdt.name = 'text'
  58. RETURNING id INTO idfieldstime;
  59. --Comentário
  60. INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
  61. SELECT fdt.id, 'Comment', 'Additional comment about the event', '', 1
  62. FROM fieldsdatatypes fdt
  63. WHERE fdt.name = 'text'
  64. RETURNING id INTO idfieldscomment;
  65. --Imagens
  66. INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
  67. SELECT fdt.id, 'Images', 'Event Images', '', 1
  68. FROM fieldsdatatypes fdt
  69. WHERE fdt.name = 'text'
  70. RETURNING id INTO idfieldsimages;
  71. --Qtd de agua no pluviometro
  72. INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
  73. SELECT fdt.id, 'Rain_amount', 'amount of rain recorded in the pluviometer', '', 1
  74. FROM fieldsdatatypes fdt
  75. WHERE fdt.name = 'real'
  76. RETURNING id INTO idfieldsvalue;
  77. --Tipo da instituição
  78. INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
  79. SELECT fdt.id, 'Institute_type', 'Kind of an institute', '', 1
  80. FROM fieldsdatatypes fdt WHERE fdt.name = 'text'
  81. RETURNING id INTO idfieldsinstype;
  82. --Nome da Instituição
  83. INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
  84. SELECT fdt.id, 'Institute_name', 'Name of an institute', '', 1
  85. FROM fieldsdatatypes fdt
  86. WHERE fdt.name = 'text'
  87. RETURNING id INTO idfieldsinsname;
  88. ---------------------------------- Formulários ---------------------------------------
  89. --Begin FloodZones Form
  90. INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active)
  91. SELECT fo.id, 'FLOODZONES_FORM', 'Flood Zones Form', 'Flood Zones Form', current_timestamp, 1
  92. FROM formsorigins fo
  93. WHERE fo.name = 'WP6.MobileApp'
  94. RETURNING id INTO idfloodzonesform;
  95. --situação
  96. INSERT INTO formsfields(id, idforms, idfields, active)
  97. VALUES (DEFAULT, idfloodzonesform, idfieldsituationcode, 1);
  98. --local (lat, log e endereço)
  99. INSERT INTO formsfields(id, idforms, idfields, active)
  100. VALUES (DEFAULT, idfloodzonesform, idfieldslatitude, 1);
  101. INSERT INTO formsfields(id, idforms, idfields, active)
  102. VALUES (DEFAULT, idfloodzonesform, idfieldslongitude, 1);
  103. INSERT INTO formsfields(id, idforms, idfields, active)
  104. VALUES (DEFAULT, idfloodzonesform, idfieldsaddress, 1);
  105. --data e hora
  106. INSERT INTO formsfields(id, idforms, idfields, active)
  107. VALUES (DEFAULT, idfloodzonesform, idfieldsdate, 1);
  108. INSERT INTO formsfields(id, idforms, idfields, active)
  109. VALUES (DEFAULT, idfloodzonesform, idfieldstime, 1);
  110. --comentário
  111. INSERT INTO formsfields(id, idforms, idfields, active)
  112. VALUES (DEFAULT, idfloodzonesform, idfieldscomment, 1);
  113. --imagens
  114. INSERT INTO formsfields(id, idforms, idfields, active)
  115. VALUES (DEFAULT, idfloodzonesform, idfieldsimages, 1);
  116. --End FloodZones Form
  117. --Begin Rain Form
  118. INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active)
  119. SELECT fo.id, 'RAIN_FORM', 'Rain', 'Rain zones Form', current_timestamp, 1
  120. FROM formsorigins fo
  121. WHERE fo.name = 'WP6.MobileApp'
  122. RETURNING id INTO idrainform;
  123. --situação
  124. INSERT INTO formsfields(id, idforms, idfields, active)
  125. VALUES (DEFAULT, idrainform, idfieldsituationcode, 1);
  126. --local (lat, log e endereço)
  127. INSERT INTO formsfields(id, idforms, idfields, active)
  128. VALUES (DEFAULT, idrainform, idfieldslatitude, 1);
  129. INSERT INTO formsfields(id, idforms, idfields, active)
  130. VALUES (DEFAULT, idrainform, idfieldslongitude, 1);
  131. INSERT INTO formsfields(id, idforms, idfields, active)
  132. VALUES (DEFAULT, idrainform, idfieldsaddress, 1);
  133. --data e hora
  134. INSERT INTO formsfields(id, idforms, idfields, active)
  135. VALUES (DEFAULT, idrainform, idfieldsdate, 1);
  136. INSERT INTO formsfields(id, idforms, idfields, active)
  137. VALUES (DEFAULT, idrainform, idfieldstime, 1);
  138. --comentário
  139. INSERT INTO formsfields(id, idforms, idfields, active)
  140. VALUES (DEFAULT, idrainform, idfieldscomment, 1);
  141. --imagens
  142. INSERT INTO formsfields(id, idforms, idfields, active)
  143. VALUES (DEFAULT, idrainform, idfieldsimages, 1);
  144. --End Rain Form
  145. --Begin Pluviometer Form
  146. INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active)
  147. SELECT fo.id, 'PLUVIOMETERS_FORM', 'Pluviometers', 'Pluviometers Form', current_timestamp, 1
  148. FROM formsorigins fo
  149. WHERE fo.name = 'WP6.MobileApp'
  150. RETURNING id INTO idpluvform;
  151. --situação
  152. INSERT INTO formsfields(id, idforms, idfields, active)
  153. VALUES (DEFAULT, idpluvform, idfieldsituationcode, 1);
  154. --local (lat, log e endereço)
  155. INSERT INTO formsfields(id, idforms, idfields, active)
  156. VALUES (DEFAULT, idpluvform, idfieldslatitude, 1);
  157. INSERT INTO formsfields(id, idforms, idfields, active)
  158. VALUES (DEFAULT, idpluvform, idfieldslongitude, 1);
  159. INSERT INTO formsfields(id, idforms, idfields, active)
  160. VALUES (DEFAULT, idpluvform, idfieldsaddress, 1);
  161. --data e hora
  162. INSERT INTO formsfields(id, idforms, idfields, active)
  163. VALUES (DEFAULT, idpluvform, idfieldsdate, 1);
  164. INSERT INTO formsfields(id, idforms, idfields, active)
  165. VALUES (DEFAULT, idpluvform, idfieldstime, 1);
  166. --comentário
  167. INSERT INTO formsfields(id, idforms, idfields, active)
  168. VALUES (DEFAULT, idpluvform, idfieldscomment, 1);
  169. --imagens
  170. INSERT INTO formsfields(id, idforms, idfields, active)
  171. VALUES (DEFAULT, idpluvform, idfieldsimages, 1);
  172. --End Pluviometer Form
  173. --Begin River Form
  174. INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active)
  175. SELECT fo.id, 'RIVERFLOOD_FORM', 'River Flood', 'River Flood Form', current_timestamp, 1
  176. FROM formsorigins fo
  177. WHERE fo.name = 'WP6.MobileApp'
  178. RETURNING id INTO idriverform;
  179. --situação
  180. INSERT INTO formsfields(id, idforms, idfields, active)
  181. VALUES (DEFAULT, idriverform, idfieldsituationcode, 1);
  182. --local (lat, log e endereço)
  183. INSERT INTO formsfields(id, idforms, idfields, active)
  184. VALUES (DEFAULT, idriverform, idfieldslatitude, 1);
  185. INSERT INTO formsfields(id, idforms, idfields, active)
  186. VALUES (DEFAULT, idriverform, idfieldslongitude, 1);
  187. INSERT INTO formsfields(id, idforms, idfields, active)
  188. VALUES (DEFAULT, idriverform, idfieldsaddress, 1);
  189. --data e hora
  190. INSERT INTO formsfields(id, idforms, idfields, active)
  191. VALUES (DEFAULT, idriverform, idfieldsdate, 1);
  192. INSERT INTO formsfields(id, idforms, idfields, active)
  193. VALUES (DEFAULT, idriverform, idfieldstime, 1);
  194. --comentário
  195. INSERT INTO formsfields(id, idforms, idfields, active)
  196. VALUES (DEFAULT, idriverform, idfieldscomment, 1);
  197. --imagens
  198. INSERT INTO formsfields(id, idforms, idfields, active)
  199. VALUES (DEFAULT, idriverform, idfieldsimages, 1);
  200. --End River Form
  201. --Pluviometer Registration Form
  202. INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active)
  203. SELECT fo.id, 'PLUVIOMETERS_REGISTRATION', 'Pluviometer registration', 'Pluviometer registration', current_timestamp, 1
  204. FROM formsorigins fo
  205. WHERE fo.name = 'WP6.MobileApp'
  206. RETURNING id INTO idpluvregsform;
  207. --local (lat, log e endereço)
  208. INSERT INTO formsfields(id, idforms, idfields, active)
  209. VALUES (DEFAULT, idpluvregsform, idfieldslatitude, 1);
  210. INSERT INTO formsfields(id, idforms, idfields, active)
  211. VALUES (DEFAULT, idpluvregsform, idfieldslongitude, 1);
  212. INSERT INTO formsfields(id, idforms, idfields, active)
  213. VALUES (DEFAULT, idpluvregsform, idfieldsaddress, 1);
  214. --data e hora
  215. INSERT INTO formsfields(id, idforms, idfields, active)
  216. VALUES (DEFAULT, idpluvregsform, idfieldsdate, 1);
  217. INSERT INTO formsfields(id, idforms, idfields, active)
  218. VALUES (DEFAULT, idpluvregsform, idfieldstime, 1);
  219. --Instituição (tipo e nome)
  220. INSERT INTO formsfields(id, idforms, idfields, active)
  221. VALUES (DEFAULT, idpluvregsform, idfieldsinstype, 1);
  222. INSERT INTO formsfields(id, idforms, idfields, active)
  223. VALUES (DEFAULT, idpluvregsform, idfieldsinsname, 1);
  224. --End Pluviometer Registration Form
  225. END $$'