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.

163 lines
4.1 KiB

3 years ago
  1. CREATE TABLE IF NOT EXISTS users (
  2. id SERIAL PRIMARY KEY,
  3. Email VARCHAR(255) UNIQUE NOT NULL,
  4. firstname VARCHAR(100) NOT NULL,
  5. surname VARCHAR(100) NOT NULL,
  6. avatar VARCHAR(100) NULL,
  7. active INT NOT NULL
  8. );
  9. CREATE TABLE IF NOT EXISTS profiles
  10. (
  11. id SERIAL PRIMARY KEY,
  12. name VARCHAR(100) NOT NULL,
  13. active INT NOT NULL
  14. );
  15. CREATE TABLE IF NOT EXISTS usersprofiles
  16. (
  17. id SERIAL PRIMARY KEY,
  18. idusers INT NOT NULL,
  19. idprofiles INT NOT NULL,
  20. active INT NOT NULL,
  21. FOREIGN KEY (idusers) REFERENCES users (id),
  22. FOREIGN KEY (idprofiles) REFERENCES profiles (id)
  23. );
  24. CREATE TABLE IF NOT EXISTS permissions
  25. (
  26. id SERIAL PRIMARY KEY,
  27. name VARCHAR(100) NOT NULL,
  28. active INT NOT NULL
  29. );
  30. CREATE TABLE IF NOT EXISTS profilespermissions
  31. (
  32. id SERIAL PRIMARY KEY,
  33. idprofiles INT NOT NULL,
  34. idpermissions INT NOT NULL,
  35. active INT NOT NULL,
  36. FOREIGN KEY (idprofiles) REFERENCES profiles (id),
  37. FOREIGN KEY (idpermissions) REFERENCES permissions (id)
  38. );
  39. CREATE TABLE IF NOT EXISTS formsorigins
  40. (
  41. id SERIAL PRIMARY KEY,
  42. name VARCHAR(100) NOT NULL,
  43. active INT NOT NULL
  44. );
  45. CREATE TABLE IF NOT EXISTS forms
  46. (
  47. id SERIAL PRIMARY KEY,
  48. idformsorigins INT NOT NULL,
  49. code VARCHAR(50) UNIQUE NOT NULL,
  50. name VARCHAR(100) NOT NULL,
  51. description VARCHAR(100) NOT NULL,
  52. dtcreation TIMESTAMP NOT NULL DEFAULT NOW(),
  53. active INT NOT NULL,
  54. FOREIGN KEY (idformsorigins) REFERENCES formsorigins (id)
  55. );
  56. CREATE TABLE IF NOT EXISTS fieldsdatatypes
  57. (
  58. id SERIAL PRIMARY KEY,
  59. name VARCHAR(100) NOT NULL,
  60. description VARCHAR(100) NOT NULL,
  61. active INT NOT NULL
  62. );
  63. CREATE TABLE IF NOT EXISTS fields
  64. (
  65. id SERIAL PRIMARY KEY,
  66. idfieldsdatatypes INT NOT NULL,
  67. name VARCHAR(100) NOT NULL,
  68. description VARCHAR(100) NOT NULL,
  69. fillingclue VARCHAR(100) NOT NULL,
  70. active INT NOT NULL,
  71. FOREIGN KEY (idfieldsdatatypes) REFERENCES fieldsdatatypes (id)
  72. );
  73. CREATE TABLE IF NOT EXISTS formsfields
  74. (
  75. id SERIAL PRIMARY KEY,
  76. idforms INT NOT NULL,
  77. idfields INT NOT NULL,
  78. active INT NOT NULL,
  79. FOREIGN KEY (idforms) REFERENCES forms (id),
  80. FOREIGN KEY (idfields) REFERENCES fields (id)
  81. );
  82. CREATE TABLE IF NOT EXISTS alternatives
  83. (
  84. id SERIAL PRIMARY KEY,
  85. response VARCHAR(100) NOT NULL,
  86. shortresponse VARCHAR(100) NOT NULL,
  87. description VARCHAR(100) NOT NULL,
  88. active INT NOT NULL
  89. );
  90. CREATE TABLE IF NOT EXISTS fieldsalternatives
  91. (
  92. id SERIAL PRIMARY KEY,
  93. idfields INT NOT NULL,
  94. idalternatives INT NOT NULL,
  95. active INT NOT NULL,
  96. FOREIGN KEY (idfields) REFERENCES fields (id),
  97. FOREIGN KEY (idalternatives) REFERENCES alternatives (id)
  98. );
  99. CREATE TABLE IF NOT EXISTS formsanswers
  100. (
  101. id SERIAL PRIMARY KEY,
  102. idforms INT NOT NULL,
  103. idusersinformer INT NOT NULL,
  104. dtfilling TIMESTAMP NOT NULL,
  105. latitude NUMERIC NULL,
  106. longitude NUMERIC NULL,
  107. FOREIGN KEY (idforms) REFERENCES forms (id),
  108. FOREIGN KEY (idusersinformer) REFERENCES users (id)
  109. );
  110. CREATE TABLE IF NOT EXISTS fieldsanswers
  111. (
  112. id SERIAL PRIMARY KEY,
  113. idfields INT NOT NULL,
  114. idformsanswers INT NOT NULL,
  115. value VARCHAR(100) NULL,
  116. FOREIGN KEY (idfields) REFERENCES fields (id),
  117. FOREIGN KEY (idformsanswers) REFERENCES formsanswers (id)
  118. );
  119. SELECT AddGeometryColumn('','fieldsanswers','geom','4326','MULTIPOLYGON',2);
  120. CREATE TABLE IF NOT EXISTS usersendorsementfieldsanswers
  121. (
  122. id SERIAL PRIMARY KEY,
  123. idusersendorsement INT NOT NULL,
  124. idfieldsanswers INT NOT NULL,
  125. latitude NUMERIC NULL,
  126. longitude NUMERIC NULL,
  127. istrustable INT NOT NULL,
  128. active INT NOT NULL,
  129. FOREIGN KEY (idusersendorsement) REFERENCES users (id),
  130. FOREIGN KEY (idfieldsanswers) REFERENCES fieldsanswers (id)
  131. );
  132. CREATE TABLE IF NOT EXISTS preliminarydata
  133. (
  134. id SERIAL PRIMARY KEY,
  135. idfieldsanswers INT NOT NULL,
  136. dtinsert TIMESTAMP NOT NULL,
  137. active INT NOT NULL,
  138. FOREIGN KEY (idfieldsanswers) REFERENCES fieldsanswers (id)
  139. );
  140. CREATE TABLE IF NOT EXISTS trusteddata
  141. (
  142. id SERIAL PRIMARY KEY,
  143. idfieldsanswers INT NOT NULL,
  144. dtinsert TIMESTAMP NOT NULL,
  145. active INT NOT NULL,
  146. FOREIGN KEY (idfieldsanswers) REFERENCES fieldsanswers (id)
  147. );