Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation process #265

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- control
paths-ignore:
- 'website/**'
- '.github/workflows/website.yml'
Expand Down Expand Up @@ -32,9 +33,9 @@ jobs:
docker run -d -p 5432:5432 --name signalo -v $(pwd):/src opengisch/signalo:unstable
docker exec signalo init_db.sh wait
docker exec -e PGSERVICE=pg_signalo_demo signalo init_db.sh build -d
docker exec signalo pg_dump --format custom --exclude-schema=public --blobs --compress 5 --file signalo-testing-db-dump-with-demo.backup signalo_demo
docker exec -e PGSERVICE=pg_signalo_demo signalo /src/scripts/all-signs.py


# - uses: actions/setup-node@v3
# with:
# node-version: '18'
Expand Down Expand Up @@ -75,15 +76,33 @@ jobs:
DEMO_DB_TESTING: ${{ secrets.DEMO_DB_TESTING }}
DEMO_DB_PASSWORD: ${{ secrets.DEMO_DB_PASSWORD }}
run: |
BACKUP_FILE=signalo-testing-db-dump-with-demo.backup
CONNECTION="--host=${DEMO_DB_HOST} --username=${DEMO_DB_USER} --port=${DEMO_DB_PORT} --dbname=${DEMO_DB_TESTING}"
export PGPASSWORD=${DEMO_DB_PASSWORD}
docker exec signalo pg_dump --format custom --exclude-schema=public --blobs --compress 5 --file ${BACKUP_FILE} signalo
psql ${CONNECTION} -c "DROP SCHEMA IF EXISTS signalo_app CASCADE; DROP SCHEMA IF EXISTS signalo_db CASCADE;"
pg_restore ${CONNECTION} --exit-on-error --clean --if-exists --no-owner ${BACKUP_FILE}
pg_restore ${CONNECTION} --exit-on-error --clean --if-exists --no-owner signalo-testing-db-dump-with-demo.backup
psql ${CONNECTION} -v EXIT_ON_ERROR=on -f ./datamodel/roles/setup.sql

- name: "failure logs"
if: failure()
run: |
docker logs signalo

- uses: actions/upload-artifact@v4
id: artifact
if: github.event_name == 'pull_request'
with:
name: signalo-pr-testing
path: |
signalo-testing-db-dump-with-demo.backup
project

- name: Schedule download comment
uses: ./.github/actions/post_sticky_comment
if: github.event_name == 'pull_request'
with:
marker: pr-testing
body: |
### Testing
Download [demo data dump and QGIS project](${{ steps.artifact.outputs.artifact-url }}).
*(Built from commit ${{ github.event.pull_request.head.sha }})*
pr: ${{ github.event.number }}
2 changes: 1 addition & 1 deletion datamodel/app/create_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def create_views(srid: int, pg_service: str):

run_sql("datamodel/app/create_schema.sql", pg_service, variables)

run_sql("datamodel/app/vw_edited_support.sql", pg_service, variables)
run_sql("datamodel/app/vw_validation.sql", pg_service, variables)
run_sql("datamodel/app/vw_azimut_edit.sql", pg_service, variables)

vw_sign_symbol(pg_service=pg_service, srid=srid)
Expand Down
24 changes: 22 additions & 2 deletions datamodel/app/vw_azimut_edit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ CREATE OR REPLACE VIEW signalo_app.vw_azimut_edit
AS
SELECT
az.id,
az._last_modification_date,
az._last_modification_user,
az.needs_validation,
ST_MakeLine(su.geometry, ST_SetSRID(St_MakePoint(ST_X(su.geometry) + 10 * sin(radians(az.azimut)), ST_Y(su.geometry) + 10 *cos(radians(az.azimut))), 2056))::geometry(LineString, 2056) as geometry
FROM signalo_db.azimut az
INNER JOIN signalo_db.support su ON az.fk_support = su.id;
Expand All @@ -25,7 +28,19 @@ CREATE FUNCTION signalo_app.ft_azimut_insert() RETURNS trigger
RAISE EXCEPTION 'Could not create a support';
END IF;
END IF;
INSERT INTO signalo_db.azimut (fk_support, azimut) VALUES (support_id, degrees(ST_Azimuth(ST_StartPoint(NEW.geometry), ST_EndPoint(NEW.geometry))));
INSERT INTO signalo_db.azimut (
fk_support,
_last_modification_date,
_last_modification_user,
needs_validation,
azimut
) VALUES (
support_id,
NEW._last_modification_date,
NEW._last_modification_user,
NEW.needs_validation,
degrees(ST_Azimuth(ST_StartPoint(NEW.geometry), ST_EndPoint(NEW.geometry)))
);
RETURN NEW;
END;
$$;
Expand All @@ -48,7 +63,12 @@ CREATE FUNCTION signalo_app.ft_azimut_update() RETURNS trigger
IF ST_NumPoints(NEW.geometry) != 2 THEN
RAISE EXCEPTION 'The line should have only 2 vertices';
END IF;
UPDATE signalo_db.azimut SET azimut = degrees(ST_Azimuth(ST_StartPoint(NEW.geometry), ST_EndPoint(NEW.geometry))) WHERE id = NEW.id;
UPDATE signalo_db.azimut SET
azimut = degrees(ST_Azimuth(ST_StartPoint(NEW.geometry), ST_EndPoint(NEW.geometry))),
_last_modification_date = NEW._last_modification_date,
_last_modification_user = NEW._last_modification_user,
needs_validation = NEW.needs_validation::boolean
WHERE id = NEW.id;
RETURN NEW;
END;
$$;
Expand Down
7 changes: 0 additions & 7 deletions datamodel/app/vw_edited_support.sql

This file was deleted.

9 changes: 7 additions & 2 deletions datamodel/app/vw_sign_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,20 @@ def vw_sign_symbol(srid: int, pg_service: str = None):
table_name="sign",
remove_pkey=False,
indent=4,
skip_columns=["rank", "fk_frame", "_edited"],
skip_columns=[
"rank",
"fk_frame",
"needs_validation",
"_last_modification_platform",
],
),
frame_columns=select_columns(
pg_cur=cursor,
table_schema="signalo_db",
table_name="frame",
remove_pkey=False,
indent=4,
skip_columns=["_edited"],
skip_columns=["needs_validation", "_last_modification_platform"],
prefix="frame_",
),
vl_official_sign_columns=select_columns(
Expand Down
28 changes: 28 additions & 0 deletions datamodel/app/vw_validation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE OR REPLACE VIEW signalo_app.vw_validation AS
SELECT
DISTINCT ON (su.id)
su.id,
su.geometry,
greatest(su._last_modification_date, a._last_modification_date, f._last_modification_date, si._last_modification_date) AS last_modification_date,
su.needs_validation or a.needs_validation or f.needs_validation or si.needs_validation AS needs_validation
FROM signalo_db.support su
LEFT JOIN (SELECT id, fk_support, needs_validation, MAX(_last_modification_date) OVER (PARTITION BY fk_support ORDER BY needs_validation DESC NULLS LAST) AS _last_modification_date FROM signalo_db.azimut ) a ON a.fk_support = su.id
LEFT JOIN (SELECT id, fk_azimut, needs_validation, MAX(_last_modification_date) OVER (PARTITION BY fk_azimut ORDER BY needs_validation DESC NULLS LAST) AS _last_modification_date FROM signalo_db.frame) f ON f.fk_azimut = a.id
LEFT JOIN (SELECT id, fk_frame, needs_validation, MAX(_last_modification_date) OVER (PARTITION BY fk_frame ORDER BY needs_validation DESC NULLS LAST) AS _last_modification_date FROM signalo_db.sign) si ON si.fk_frame = f.id;

CREATE FUNCTION signalo_app.ft_validation_update() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE signalo_db.support SET needs_validation = NEW.needs_validation WHERE id = NEW.id;
UPDATE signalo_db.azimut SET needs_validation = NEW.needs_validation WHERE fk_support = NEW.id;
UPDATE signalo_db.frame fr SET needs_validation = NEW.needs_validation FROM signalo_db.azimut az WHERE fr.fk_azimut = az.id AND az.fk_support = NEW.id;
UPDATE signalo_db.sign si SET needs_validation = NEW.needs_validation FROM signalo_db.frame fr, signalo_db.azimut az WHERE si.fk_frame = fr.id AND fr.fk_azimut = az.id AND az.fk_support = NEW.id;
RETURN NEW;
END;
$$;

CREATE TRIGGER azimut_update
INSTEAD OF UPDATE ON signalo_app.vw_validation
FOR EACH ROW
EXECUTE FUNCTION signalo_app.ft_validation_update();
34 changes: 34 additions & 0 deletions datamodel/changelogs/0102/0101_02_control.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ALTER TABLE signalo_db.support DROP COLUMN _edited;
ALTER TABLE signalo_db.azimut DROP COLUMN _edited;
ALTER TABLE signalo_db.frame DROP COLUMN _edited;
ALTER TABLE signalo_db.sign DROP COLUMN _edited;

ALTER TABLE signalo_db.support ADD COLUMN needs_validation boolean not null default false;
ALTER TABLE signalo_db.azimut ADD COLUMN needs_validation boolean not null default false;
ALTER TABLE signalo_db.frame ADD COLUMN needs_validation boolean not null default false;
ALTER TABLE signalo_db.sign ADD COLUMN needs_validation boolean not null default false;

ALTER TABLE signalo_db.support ADD COLUMN _last_modification_platform text default null;
ALTER TABLE signalo_db.azimut ADD COLUMN _last_modification_platform text default null;
ALTER TABLE signalo_db.frame ADD COLUMN _last_modification_platform text default null;
ALTER TABLE signalo_db.sign ADD COLUMN _last_modification_platform text default null;

ALTER TABLE signalo_db.support RENAME COLUMN _last_modified_date TO _last_modification_date;
ALTER TABLE signalo_db.azimut RENAME COLUMN _last_modified_date TO _last_modification_date;
ALTER TABLE signalo_db.frame RENAME COLUMN _last_modified_date TO _last_modification_date;
ALTER TABLE signalo_db.sign RENAME COLUMN _last_modified_date TO _last_modification_date;

ALTER TABLE signalo_db.support RENAME COLUMN _last_modified_user TO _last_modification_user;
ALTER TABLE signalo_db.azimut RENAME COLUMN _last_modified_user TO _last_modification_user;
ALTER TABLE signalo_db.frame RENAME COLUMN _last_modified_user TO _last_modification_user;
ALTER TABLE signalo_db.sign RENAME COLUMN _last_modified_user TO _last_modification_user;

ALTER TABLE signalo_db.support RENAME COLUMN _inserted_date TO _creation_date;
ALTER TABLE signalo_db.azimut RENAME COLUMN _inserted_date TO _creation_date;
ALTER TABLE signalo_db.frame RENAME COLUMN _inserted_date TO _creation_date;
ALTER TABLE signalo_db.sign RENAME COLUMN _inserted_date TO _creation_date;

ALTER TABLE signalo_db.support RENAME COLUMN _inserted_user TO _creation_user;
ALTER TABLE signalo_db.azimut RENAME COLUMN _inserted_user TO _creation_user;
ALTER TABLE signalo_db.frame RENAME COLUMN _inserted_user TO _creation_user;
ALTER TABLE signalo_db.sign RENAME COLUMN _inserted_user TO _creation_user;
Loading