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 ``` 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 ); 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) &