Skip to content

Commit

Permalink
Update job.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
georgepstaylor committed Jul 26, 2024
1 parent 7c3892d commit c988192
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions jobs/refresh-db/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,9 @@ data:
# Dump the source database
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 \
EXECUTE (SELECT string_agg('DROP TABLE IF EXISTS public.' || tablename || ' CASCADE;', ' ') \
FROM pg_tables WHERE schemaname = 'public'); \
END \$\$;" 2> >(tee ~/error.log >&2)
psql --host="$DST_DB_HOST" --username="$DST_DB_USER" --dbname="$DST_DB_NAME" -c "drop schema public cascade;" 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 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)
psql --host="$DST_DB_HOST" --username="$DST_DB_USER" --dbname="$DST_DB_NAME" -c "create schema public;" 2> >(tee ~/error.log >&2)
# Restore the source database dump to the destination database
pg_restore --jobs=4 --host="$DST_DB_HOST" --username="$DST_DB_USER" --dbname="$DST_DB_NAME" --no-owner --no-privileges --verbose /home/job/db-dump 2> >(tee ~/error.log >&2)
Expand Down

0 comments on commit c988192

Please sign in to comment.