Files
threshold/testing/dbtest/docker/restore-benchmark-dumps.sh
T
Johan Brandhorst-Satzkorn 5d042c7ec7 feat(dbtest): Mount DB dumps and create templates
Mount the benchmark dump directory when running
the test database and create a new script for creating
templates from the dumps. This makes it easy to create
pre-populated databases for benchmark tests.

Fixes https://hashicorp.atlassian.net/browse/ICU-4040
2022-04-29 16:33:44 -04:00

17 lines
705 B
Bash

#!/usr/bin/env bash
set -e
shopt -s globstar
for file in $(ls -v /benchmark_dumps/*.dump); do
echo "Creating template database based on: ${file}"
db_name="boundary_$(basename ${file} .dump)_template"
psql -v "ON_ERROR_STOP=1" --username "$POSTGRES_USER" --dbname "${POSTGRES_DB}" -q <<EOSQL
create database ${db_name} owner ${POSTGRES_USER};
EOSQL
echo "Restoring ${file} into ${db_name}"
pg_restore -j $(nproc) --username "${POSTGRES_USER}" --dbname ${db_name} "${file}"
psql -v "ON_ERROR_STOP=1" --username "${POSTGRES_USER}" --dbname "${POSTGRES_DB}" -q <<EOSQL
update pg_database set datistemplate = true, datallowconn = false where datname = '${db_name}';
EOSQL
done