fuel-db: customer on every row, place and holder for site, licence tables
Draft migrations rewritten in place (PD-16, PD-18), with 0004 for the licence tables (PD-20) and rule tests in fuel-db/tests. Dashboards' column list regenerated; coverage_detail selects operator_uid. Checks: tests/run.sh 106 of 106; 18 views, 686 rows, 0 differences against a reference from the same corpus. Codex's fixes to its inspection are not re-inspected. Bands: persistence, Superset. Rules: 6, 8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e4806f5799
commit
ab553526f6
11 files changed
+1197
-398
No files matched your search
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/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 <<SQL
|
||||
DO \$\$ BEGIN
|
||||
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '$loader') THEN
|
||||
CREATE ROLE $loader LOGIN;
|
||||
GRANT fuel_owner TO $loader WITH INHERIT FALSE, SET TRUE;
|
||||
ALTER ROLE $loader SET role TO 'fuel_owner';
|
||||
END IF;
|
||||
END \$\$;
|
||||
ALTER DATABASE $db OWNER TO fuel_owner;
|
||||
GRANT CONNECT ON DATABASE $db TO fuel_ro;
|
||||
SQL
|
||||
psql_as postgres -d "$db" >/dev/null <<SQL
|
||||
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
|
||||
GRANT USAGE ON SCHEMA public TO fuel_ro;
|
||||
ALTER DEFAULT PRIVILEGES FOR ROLE fuel_owner IN SCHEMA public GRANT SELECT ON TABLES TO fuel_ro;
|
||||
SQL
|
||||
|
||||
for file in "$here"/../migrations/*.sql; do
|
||||
psql_as "$loader" -d "$db" <"$file" >/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: //'
|
||||
Reference in new issue
Block a user