Files
loki/scripts/hetzner/provisionable-db.sh
CatoandClaude 987f77d61b feat(box): an accounts database beside a supabase schema (#1562)
Printcraft and Botsmann keep their data in a schema of the supabase-db
container, which publishes no port, so AccountKit (Drizzle) cannot reach
it. scripts/hetzner/accounts-db.conf (app|database) gives such an app a
second, host database for its accounts, without a new apps.conf column:

- provisionable-db.sh accepts a supabase app with a row, so
  provision-db.yml creates its database, role and DATABASE_URL;
- deploy.sh applies drizzle/ to that database in its own step after the
  schema step; apply-schema.sh takes ONLY_LAYOUT, and a supabase schema
  only ever takes supabase/migrations;
- check-accounts-db.sh (in verify) fails when the file drifts from
  apps.conf: unknown, archived, non-supabase, misnamed, duplicate or
  colliding rows;
- accountkit-supabase.yml / accountkit-supabase.sh survey, rehearse
  (always rolled back) and import an app's GoTrue people as AccountKit
  accounts under their old ids, linked to OrangeCat by actor id, never by
  address. Counts only; nothing empties a table.

test-accounts-db.sh (in test:ops) covers the register, the gate, the
layout split, the deploy order and the import's refusals.


Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-02 21:53:29 +01:00

53 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# provisionable-db.sh <app> — print the host database provision-db-on-box.sh
# would create for <app>, or refuse.
#
# The gate in front of .github/workflows/provision-db.yml. provision-db-on-box.sh
# takes any slug and derives the database from it (`-` → `_`); from a laptop the
# person running it knows which apps that is right for. A workflow input does
# not, so this answers from the register instead:
#
# - the app must have an apps.conf row;
# - its `db` column must be a HOST database name — not '-' (no database) and
# not `supabase:<schema>` (that lives in the supabase-db container, which
# this script does not touch), unless accounts-db.conf gives that app a
# host accounts database beside its schema: then that one is provisioned;
# - that name must be the one the script derives from the slug. A row like
# `revamp-info|…|hirnli` is provisioned under another name; running the
# script for it would make a second, empty `revamp_info` database next to
# the real one and point nothing at it.
#
# Prints names only (an app and a database name are not secrets).
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
source "$HERE/lib.sh"
APP="${1:-}"
[[ "$APP" =~ ^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$ ]] || {
echo "app name must be a slug ([a-z0-9-]): '$APP'" >&2; exit 2; }
app_lookup "$APP" || exit 1
case "$DB" in
""|-) echo "$APP has no database in apps.conf (db column '-'); nothing to provision" >&2; exit 1 ;;
supabase:*)
# Its data stays in the supabase-db container. A row in accounts-db.conf
# gives it a host database for its accounts beside that schema; without
# one there is nothing here to provision.
accounts="$(accounts_db_of "$APP")"
[ -n "$accounts" ] || {
echo "$APP lives in the supabase-db container ($DB) and has no accounts database in accounts-db.conf; provision-db-on-box.sh is for host databases only" >&2; exit 1; }
DB="$accounts" ;;
esac
[[ "$DB" =~ ^[a-z][a-z0-9_]{0,62}$ ]] || {
echo "$APP's db column '$DB' is not a plain host database name" >&2; exit 1; }
derived="${APP//-/_}"
[ "$DB" = "$derived" ] || {
echo "$APP's register database is '$DB', but provision-db-on-box.sh would create '$derived'; refusing" >&2; exit 1; }
[ "${STATUS:-}" != archived ] || { echo "$APP is archived; refusing" >&2; exit 1; }
printf '%s\n' "$DB"