Browse Source

Merge branch 'main' of github.com:IGSD-UoW/WPD-MobileApp

master
GabrielTrettel 3 years ago
parent
commit
4acef1c24a
  1. 1
      README.md
  2. 19
      db/0.services.sys_config.sql
  3. 88
      db/1.sys_config.sql
  4. 163
      db/services.ddl.sql
  5. BIN
      db/services.erd.pdf

1
README.md

@ -17,6 +17,7 @@ This project contains the components developed for a mobile app within the Water
. .
├── LICENSE # License description file ├── LICENSE # License description file
├── README.md # Readme description file ├── README.md # Readme description file
└── db # database files
└── src # source files └── src # source files
├── App.js # app initial file ├── App.js # app initial file
├── app # app custom folders and files ├── app # app custom folders and files

19
db/0.services.sys_config.sql

@ -0,0 +1,19 @@
DO $$
BEGIN
INSERT INTO users(email, firstname, surname, active) VALUES ('admin@wpd.com', 'admin', 'wpd', 1);
INSERT INTO formsorigins(id, name, active) VALUES (DEFAULT, 'OFICIAL', 1);
INSERT INTO formsorigins(id, name, active) VALUES (DEFAULT, 'WP6.MobileApp', 1);
INSERT INTO fieldsdatatypes(id, name, description, active) VALUES (DEFAULT, 'integer', 'data type integer', 1);
INSERT INTO fieldsdatatypes(id, name, description, active) VALUES (DEFAULT, 'text', 'data type text', 1);
INSERT INTO fieldsdatatypes(id, name, description, active) VALUES (DEFAULT, 'real', 'data type real', 1);
INSERT INTO fieldsdatatypes(id, name, description, active) VALUES (DEFAULT, 'timestamp', 'data type timestamp', 1);
INSERT INTO fieldsdatatypes(id, name, description, active) VALUES (DEFAULT, 'geom', 'data type geometric', 1);
END $$;
--delete from formsfields;
--delete from fields;
--delete from forms;
--delete from fieldsdatatypes;
--delete from formsorigins;

88
db/1.sys_config.sql

@ -0,0 +1,88 @@
DO $$
DECLARE
idformsoriginsinserted bigint;
idformsinserted bigint;
idfieldsinserted bigint;
BEGIN
SELECT id FROM formsorigins INTO idformsoriginsinserted WHERE name = 'WP6.MobileApp' and active = 1;
--BEGIN FLOODZONES_FORM
INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active) values (idformsoriginsinserted, "FLOODZONES_FORM", "Flood Zones", "Flood Zones Form", DateTime(), 1)
RETURNING id INTO idformsinserted;
INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
SELECT fdt.id, 'id', 'id From FloodZones Form', '', 1 FROM fieldsdatatypes fdt WHERE fdt.name = 'integer'
RETURNING id INTO idfieldsinserted;
INSERT INTO formsfields(id, idforms, idfields, active) VALUES (DEFAULT, idformsinserted, idfieldsinserted, 1);
INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
SELECT fdt.id, 'description', 'description From FloodZones Form', '', 1 FROM fieldsdatatypes fdt WHERE fdt.name = 'text'
RETURNING id INTO idfieldsinserted;
INSERT INTO formsfields(id, idforms, idfields, active) VALUES (DEFAULT, idformsinserted, idfieldsinserted, 1);
INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
SELECT fdt.id, 'Images', 'Images From FloodZones Form', '', 1 FROM fieldsdatatypes fdt WHERE fdt.name = 'text'
RETURNING id INTO idfieldsinserted;
INSERT INTO formsfields(id, idforms, idfields, active) VALUES (DEFAULT, idformsinserted, idfieldsinserted, 1);
INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
SELECT fdt.id, 'Latitude', 'Latitude From FloodZones Form', '', 1 FROM fieldsdatatypes fdt WHERE fdt.name = 'real'
RETURNING id INTO idfieldsinserted;
INSERT INTO formsfields(id, idforms, idfields, active) VALUES (DEFAULT, idformsinserted, idfieldsinserted, 1);
INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
SELECT fdt.id, 'Longitude', 'Longitude From FloodZones Form', '', 1 FROM fieldsdatatypes fdt WHERE fdt.name = 'real'
RETURNING id INTO idfieldsinserted;
INSERT INTO formsfields(id, idforms, idfields, active) VALUES (DEFAULT, idformsinserted, idfieldsinserted, 1);
INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
SELECT fdt.id, 'Passable', 'Passable From FloodZones Form', '', 1 FROM fieldsdatatypes fdt WHERE fdt.name = 'integer'
RETURNING id INTO idfieldsinserted;
INSERT INTO formsfields(id, idforms, idfields, active) VALUES (DEFAULT, idformsinserted, idfieldsinserted, 1);
INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
SELECT fdt.id, 'Date', 'Date From FloodZones Form', '', 1 FROM fieldsdatatypes fdt WHERE fdt.name = 'text'
RETURNING id INTO idfieldsinserted;
INSERT INTO formsfields(id, idforms, idfields, active) VALUES (DEFAULT, idformsinserted, idfieldsinserted, 1);
INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
SELECT fdt.id, 'Time', 'Time From FloodZones Form', '', 1 FROM fieldsdatatypes fdt WHERE fdt.name = 'text'
RETURNING id INTO idfieldsinserted;
INSERT INTO formsfields(id, idforms, idfields, active) VALUES (DEFAULT, idformsinserted, idfieldsinserted, 1);
INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active)
SELECT fdt.id, 'Address', 'Address From FloodZones Form', '', 1 FROM fieldsdatatypes fdt WHERE fdt.name = 'text'
RETURNING id INTO idfieldsinserted;
INSERT INTO formsfields(id, idforms, idfields, active) VALUES (DEFAULT, idformsinserted, idfieldsinserted, 1);
--END FLOODZONES_FORM
--BEGIN PLUVIOMETERS_FORM
INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active) values (idformsoriginsinserted, "PLUVIOMETERS_FORM", "Pluviometers", "Pluviometers Form", DateTime(), 1);
--END PLUVIOMETERS_FORM
--BEGIN RAIN_FORM
INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active) values (idformsoriginsinserted, "RAIN_FORM", "Rain", "Rain zones Form", DateTime(), 1);
--END RAIN_FORM
--BEGIN RIVERFLOOD_FORM
INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active) values (idformsoriginsinserted, "RIVERFLOOD_FORM", "River Flood", "River Flood Form", DateTime(), 1);
--END RIVERFLOOD_FORM
--BEGIN PLUVIOMETERS_REGISTRATION
INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active) values (idformsoriginsinserted, "PLUVIOMETERS_REGISTRATION", "Pluviometer registration", "Pluviometer registration", DateTime(), 1);
--END PLUVIOMETERS_REGISTRATION
END $$;

163
db/services.ddl.sql

@ -0,0 +1,163 @@
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
Email VARCHAR(255) UNIQUE NOT NULL,
firstname VARCHAR(100) NOT NULL,
surname VARCHAR(100) NOT NULL,
avatar VARCHAR(100) NULL,
active INT NOT NULL
);
CREATE TABLE IF NOT EXISTS profiles
(
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
active INT NOT NULL
);
CREATE TABLE IF NOT EXISTS usersprofiles
(
id SERIAL PRIMARY KEY,
idusers INT NOT NULL,
idprofiles INT NOT NULL,
active INT NOT NULL,
FOREIGN KEY (idusers) REFERENCES users (id),
FOREIGN KEY (idprofiles) REFERENCES profiles (id)
);
CREATE TABLE IF NOT EXISTS permissions
(
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
active INT NOT NULL
);
CREATE TABLE IF NOT EXISTS profilespermissions
(
id SERIAL PRIMARY KEY,
idprofiles INT NOT NULL,
idpermissions INT NOT NULL,
active INT NOT NULL,
FOREIGN KEY (idprofiles) REFERENCES profiles (id),
FOREIGN KEY (idpermissions) REFERENCES permissions (id)
);
CREATE TABLE IF NOT EXISTS formsorigins
(
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
active INT NOT NULL
);
CREATE TABLE IF NOT EXISTS forms
(
id SERIAL PRIMARY KEY,
idformsorigins INT NOT NULL,
code VARCHAR(50) UNIQUE NOT NULL,
name VARCHAR(100) NOT NULL,
description VARCHAR(100) NOT NULL,
dtcreation TIMESTAMP NOT NULL DEFAULT NOW(),
active INT NOT NULL,
FOREIGN KEY (idformsorigins) REFERENCES formsorigins (id)
);
CREATE TABLE IF NOT EXISTS fieldsdatatypes
(
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description VARCHAR(100) NOT NULL,
active INT NOT NULL
);
CREATE TABLE IF NOT EXISTS fields
(
id SERIAL PRIMARY KEY,
idfieldsdatatypes INT NOT NULL,
name VARCHAR(100) NOT NULL,
description VARCHAR(100) NOT NULL,
fillingclue VARCHAR(100) NOT NULL,
active INT NOT NULL,
FOREIGN KEY (idfieldsdatatypes) REFERENCES fieldsdatatypes (id)
);
CREATE TABLE IF NOT EXISTS formsfields
(
id SERIAL PRIMARY KEY,
idforms INT NOT NULL,
idfields INT NOT NULL,
active INT NOT NULL,
FOREIGN KEY (idforms) REFERENCES forms (id),
FOREIGN KEY (idfields) REFERENCES fields (id)
);
CREATE TABLE IF NOT EXISTS alternatives
(
id SERIAL PRIMARY KEY,
response VARCHAR(100) NOT NULL,
shortresponse VARCHAR(100) NOT NULL,
description VARCHAR(100) NOT NULL,
active INT NOT NULL
);
CREATE TABLE IF NOT EXISTS fieldsalternatives
(
id SERIAL PRIMARY KEY,
idfields INT NOT NULL,
idalternatives INT NOT NULL,
active INT NOT NULL,
FOREIGN KEY (idfields) REFERENCES fields (id),
FOREIGN KEY (idalternatives) REFERENCES alternatives (id)
);
CREATE TABLE IF NOT EXISTS formsanswers
(
id SERIAL PRIMARY KEY,
idforms INT NOT NULL,
idusersinformer INT NOT NULL,
dtfilling TIMESTAMP NOT NULL,
latitude NUMERIC NULL,
longitude NUMERIC NULL,
FOREIGN KEY (idforms) REFERENCES forms (id),
FOREIGN KEY (idusersinformer) REFERENCES users (id)
);
CREATE TABLE IF NOT EXISTS fieldsanswers
(
id SERIAL PRIMARY KEY,
idfields INT NOT NULL,
idformsanswers INT NOT NULL,
value VARCHAR(100) NULL,
FOREIGN KEY (idfields) REFERENCES fields (id),
FOREIGN KEY (idformsanswers) REFERENCES formsanswers (id)
);
SELECT AddGeometryColumn('','fieldsanswers','geom','4326','MULTIPOLYGON',2);
CREATE TABLE IF NOT EXISTS usersendorsementfieldsanswers
(
id SERIAL PRIMARY KEY,
idusersendorsement INT NOT NULL,
idfieldsanswers INT NOT NULL,
latitude NUMERIC NULL,
longitude NUMERIC NULL,
istrustable INT NOT NULL,
active INT NOT NULL,
FOREIGN KEY (idusersendorsement) REFERENCES users (id),
FOREIGN KEY (idfieldsanswers) REFERENCES fieldsanswers (id)
);
CREATE TABLE IF NOT EXISTS preliminarydata
(
id SERIAL PRIMARY KEY,
idfieldsanswers INT NOT NULL,
dtinsert TIMESTAMP NOT NULL,
active INT NOT NULL,
FOREIGN KEY (idfieldsanswers) REFERENCES fieldsanswers (id)
);
CREATE TABLE IF NOT EXISTS trusteddata
(
id SERIAL PRIMARY KEY,
idfieldsanswers INT NOT NULL,
dtinsert TIMESTAMP NOT NULL,
active INT NOT NULL,
FOREIGN KEY (idfieldsanswers) REFERENCES fieldsanswers (id)
);

BIN
db/services.erd.pdf

Loading…
Cancel
Save