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

Clean up view-sync database #1561

Merged
merged 3 commits into from
Oct 1, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/view-sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
4 changes: 2 additions & 2 deletions src/view-sync/db-init/04_delete_from_borehole.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
8 changes: 0 additions & 8 deletions src/view-sync/db-init/06_pg_restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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) &

18 changes: 18 additions & 0 deletions src/view-sync/db-init/07_cleanup.sh
Original file line number Diff line number Diff line change
@@ -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;
"
18 changes: 18 additions & 0 deletions src/view-sync/db-init/08_exit.sh
Original file line number Diff line number Diff line change
@@ -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) &
Loading