From cec6575689bd558edd7dcffff9b4cbc8d6fdd30e Mon Sep 17 00:00:00 2001 From: Oliver Gut Date: Mon, 30 Sep 2024 17:03:09 +0200 Subject: [PATCH 1/3] Fix code indentation --- src/view-sync/db-init/04_delete_from_borehole.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/view-sync/db-init/04_delete_from_borehole.sql b/src/view-sync/db-init/04_delete_from_borehole.sql index dffc1b371..52a555111 100644 --- a/src/view-sync/db-init/04_delete_from_borehole.sql +++ b/src/view-sync/db-init/04_delete_from_borehole.sql @@ -43,8 +43,8 @@ DELETE FROM bdms.borehole WHERE id_bho NOT IN ( JOIN bdms.workflow ON workflow.id_bho_fk = borehole.id_bho JOIN bdms.roles ON roles.id_rol = workflow.id_rol_fk WHERE workflow.id_wkf IN (SELECT MAX(id_wkf) FROM bdms.workflow GROUP BY id_bho_fk) - AND finished_wkf IS NOT NULL -- get latest publication status - AND roles.name_rol = 'PUBLIC' -- publication status: published + AND finished_wkf IS NOT NULL -- get latest publication status + AND roles.name_rol = 'PUBLIC' -- publication status: published AND codelist.schema_cli = 'restriction' AND codelist.code_cli = 'f' -- restriction: free ); From 1ee4dd194d490211f96f6d43c715699c84efb1e6 Mon Sep 17 00:00:00 2001 From: Oliver Gut Date: Tue, 1 Oct 2024 07:14:51 +0200 Subject: [PATCH 2/3] Update README Ensure Docker volumes get cleaned-up prior running view-sync. Otherwise PostgreSQL database initialization scripts will not run. Also make shure new scripts gets included when running view-sync (`--build`). --- src/view-sync/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view-sync/README.md b/src/view-sync/README.md index ca577e45c..76c81e58f 100644 --- a/src/view-sync/README.md +++ b/src/view-sync/README.md @@ -11,5 +11,5 @@ docker compose -f docker-compose.services.yml up --wait # Start the view-sync container -docker compose up +docker compose down && docker compose up --build ``` From 00a74f7a16ce1d6a7047484c346a9fdb17a9975d Mon Sep 17 00:00:00 2001 From: Oliver Gut Date: Tue, 1 Oct 2024 07:41:44 +0200 Subject: [PATCH 3/3] Clean-up temporary view-sync database --- src/view-sync/db-init/06_pg_restore.sh | 8 -------- src/view-sync/db-init/07_cleanup.sh | 18 ++++++++++++++++++ src/view-sync/db-init/08_exit.sh | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 src/view-sync/db-init/07_cleanup.sh create mode 100644 src/view-sync/db-init/08_exit.sh diff --git a/src/view-sync/db-init/06_pg_restore.sh b/src/view-sync/db-init/06_pg_restore.sh index c70b6a273..557ca4922 100755 --- a/src/view-sync/db-init/06_pg_restore.sh +++ b/src/view-sync/db-init/06_pg_restore.sh @@ -32,11 +32,3 @@ pg_restore \ --no-owner \ --no-privileges \ --no-comments $DB_BACKUP_PATH - -echo "Successfully restored the $TARGET_DB_NAME database." - -# Due to some magic in the postgres docker entrypoint, the shutdown of the -# database server gets delayed to ensure database initialization. -# Afterward, the container stops gracefully with exit code 0. -(sleep 10 && pg_ctl stop -m smart) & - diff --git a/src/view-sync/db-init/07_cleanup.sh b/src/view-sync/db-init/07_cleanup.sh new file mode 100644 index 000000000..0720d0fa3 --- /dev/null +++ b/src/view-sync/db-init/07_cleanup.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# ------------------------------------------------------------------------------ +# DESCRIPTION: As part of the docker-entrypoint initialization, this script +# cleans-up the local database which is not used anymore. +# ------------------------------------------------------------------------------ + +set -e + +unset PGPASSWORD + +psql \ + --dbname=$POSTGRES_DB \ + --username=$POSTGRES_USER \ + --no-password \ + --command=" + DROP SCHEMA IF EXISTS $SOURCE_DB_SCHEMA CASCADE; + " diff --git a/src/view-sync/db-init/08_exit.sh b/src/view-sync/db-init/08_exit.sh new file mode 100644 index 000000000..6641d8bc2 --- /dev/null +++ b/src/view-sync/db-init/08_exit.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# ------------------------------------------------------------------------------ +# DESCRIPTION: As part of the docker-entrypoint initialization, this script +# gracefully exits the Docker container after all tasks have been +# completed successfully. +# ------------------------------------------------------------------------------ + +set -e + +unset PGPASSWORD + +echo "Successfully restored the $TARGET_DB_NAME database." + +# Due to some magic in the Postgres Docker entrypoint, the shutdown of the +# database server gets delayed to ensure proper database initialization. +# Afterward, the Docker container stops gracefully with exit code 0. +(sleep 10 && pg_ctl stop -m smart) &