From a46c4ba006eef2786b3c22fe512fe323a3f2ff53 Mon Sep 17 00:00:00 2001 From: George Taylor Date: Fri, 26 Jul 2024 18:09:01 +0100 Subject: [PATCH] Update job.yaml --- jobs/refresh-db/templates/job.yaml | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/jobs/refresh-db/templates/job.yaml b/jobs/refresh-db/templates/job.yaml index 9665b25..336c613 100644 --- a/jobs/refresh-db/templates/job.yaml +++ b/jobs/refresh-db/templates/job.yaml @@ -31,18 +31,28 @@ data: pg_dump --jobs=4 --host="$SRC_DB_HOST" --username="$SRC_DB_USER" --dbname="$SRC_DB_NAME" --no-owner --no-privileges --verbose --format=directory --file=/home/job/db-dump 2> >(tee ~/error.log >&2) # Drop the destination database - psql --host="$DST_DB_HOST" --username="$DST_DB_USER" --dbname="$DST_DB_NAME" -c "DO \$\$ BEGIN \ - -- Drop all tables \ - EXECUTE (SELECT string_agg('DROP TABLE IF EXISTS public.' || tablename || ' CASCADE;', ' ') \ - FROM pg_tables WHERE schemaname = 'public'); \ - -- Drop all sequences \ - EXECUTE (SELECT string_agg('DROP SEQUENCE IF EXISTS public.' || sequencename || ' CASCADE;', ' ') \ - FROM pg_sequences WHERE schemaname = 'public'); \ - -- Drop all views \ - EXECUTE (SELECT string_agg('DROP VIEW IF EXISTS public.' || viewname || ' CASCADE;', ' ') \ - FROM pg_views WHERE schemaname = 'public'); \ + psql --host="$DST_DB_HOST" --username="$DST_DB_USER" --dbname="$DST_DB_NAME" -c "\ + DO \$\$ \ + BEGIN \ + EXECUTE (SELECT string_agg('DROP TABLE IF EXISTS public.' || tablename || ' CASCADE;', ' ') \ + FROM pg_tables WHERE schemaname = 'public'); \ + END \$\$;" 2> >(tee ~/error.log >&2)s + + psql --host="$DST_DB_HOST" --username="$DST_DB_USER" --dbname="$DST_DB_NAME" -c "\ + DO \$\$ \ + BEGIN \ + EXECUTE (SELECT string_agg('DROP SEQUENCE IF EXISTS public.' || sequencename || ' CASCADE;', ' ') \ + FROM pg_sequences WHERE schemaname = 'public'); \ + END \$\$;" 2> >(tee ~/error.log >&2) + + psql --host="$DST_DB_HOST" --username="$DST_DB_USER" --dbname="$DST_DB_NAME" -c "\ + DO \$\$ \ + BEGIN \ + EXECUTE (SELECT string_agg('DROP VIEW IF EXISTS public.' || viewname || ' CASCADE;', ' ') \ + FROM pg_views WHERE schemaname = 'public'); \ END \$\$;" 2> >(tee ~/error.log >&2) + # Create the destination database createdb -w --host="$DST_DB_HOST" --username="$DST_DB_USER" "$DST_DB_NAME" 2> >(tee ~/error.log >&2)