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
This commit is contained in:
Johan Brandhorst-Satzkorn authored and Timothy Messier committed 2022-04-29 16:33:44 -04:00
1 parent 9e424db0a3
commit 5d042c7ec7
6 files changed
+21

No files matched your search

@@ -0,0 +1,16 @@
#!/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