#!/usr/bin/env bash # Applies the migrations to a throw-away database and runs the rule tests. Synthetic data only. # Needs a running fuel-db container with this repository's roles (fuel_owner, fuel_ro), e.g. the # local stack: FUEL_DB_CONTAINER=fmdb-scratch-db stacks/fuel-monitoring/fuel-db/tests/run.sh # Never point it at the server: it creates a role and a database. set -euo pipefail here=$(cd "$(dirname "$0")" && pwd) container=${FUEL_DB_CONTAINER:?set FUEL_DB_CONTAINER to a local fuel-db container} db=fuel_rules_$$ loader=fuel_rules_loader psql_as() { local user=$1 shift docker exec -i "$container" psql -X -q -v ON_ERROR_STOP=1 -U "$user" "$@" } cleanup() { psql_as postgres -d postgres -c "DROP DATABASE IF EXISTS $db;" >/dev/null } trap cleanup EXIT psql_as postgres -d postgres -c "CREATE DATABASE $db;" >/dev/null psql_as postgres -d postgres >/dev/null </dev/null </dev/null done echo "migrations applied: $(cd "$here/../migrations" && echo *.sql)" psql_as "$loader" -d "$db" <"$here/rules.sql" psql_as fuel_ro -d "$db" <"$here/read_only.sql" 2>&1 | sed 's/^psql:[^ ]* NOTICE: //'