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.

146 lines
3.7 KiB

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