mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 07:38:43 +01:00
The product, its assistant, the repo, the host and every unit on the box now share one name. 638 files, ~3,000 mentions: UI copy, config, env keys (FLEETCROWN_* -> LOKI_*), systemd units (fleetcrown-* -> loki-*), docs, articles, the deploy workflow other repos reuse, and nine file names. - Three article slugs carried the old name and had been shared; permanent redirects keep those links alive (next.config.ts). - test-no-retired-name.sh now also forbids the old product name across the whole repo, so the rename cannot creep back through templates and examples. - ASSISTANT_STACK collapses the product and the assistant into one entry, because they are now the same name. Infra was cut over ahead of this merge: /opt/loki, loki-* units, the `loki` database and role, loki.orangecat.ch (old host 308s to it; /api, /widget, /embed keep proxying), GitHub repos bitbaum/loki and bitbaum/loki-releases. The Resend sending domain stays fleetcrown.orangecat.ch until the new domain is verified in DNS. Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
39 lines
1.8 KiB
Bash
Executable File
39 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# apply-box.sh — apply a SQL/DDL file to the box Loki DB, THE RIGHT WAY.
|
|
#
|
|
# WHY: the reflex — `ssh box; sudo -u postgres psql -d loki -f x.sql` —
|
|
# creates objects OWNED BY postgres. `information_schema` is privilege-filtered,
|
|
# so the `loki` app role sees zero columns on those tables: the deploy
|
|
# drift-check false-fails and rolls back, and at runtime the app 500s with
|
|
# "permission denied for table". This cost two rollbacks (see memory
|
|
# pattern-box-ddl-owner-grant). Applying AS THE APP ROLE makes every created
|
|
# object owned by `loki` automatically — no ALTER OWNER, no invisibility.
|
|
#
|
|
# It connects with the app's own DATABASE_URL (read from the box .env), so the
|
|
# CREATE runs as `loki` over TCP even though the ssh is root.
|
|
#
|
|
# Usage: bash scripts/db/apply-box.sh <file.sql> (or: npm run db:apply-box -- <file.sql>)
|
|
set -euo pipefail
|
|
|
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")/../hetzner" && pwd)/_box-env.sh" # BOX_ROOT
|
|
|
|
FILE="${1:?usage: apply-box.sh <file.sql>}"
|
|
[ -f "$FILE" ] || { echo "apply-box: no such file: $FILE" >&2; exit 1; }
|
|
BASENAME="$(basename "$FILE")"
|
|
REMOTE_TMP="/tmp/apply-box-${BASENAME}"
|
|
|
|
echo "→ apply-box: shipping $BASENAME to $BOX_ROOT"
|
|
scp -q "$FILE" "$BOX_ROOT:$REMOTE_TMP"
|
|
|
|
ssh "$BOX_ROOT" "REMOTE_TMP='$REMOTE_TMP' BASENAME='$BASENAME' LC_ALL=C bash -s" <<'REMOTE'
|
|
set -euo pipefail
|
|
DBURL=$(grep -oP '^DATABASE_URL=\K.*' /opt/loki/app/.env 2>/dev/null | head -1 | tr -d '"')
|
|
[ -n "$DBURL" ] || { echo "apply-box: could not read box DATABASE_URL" >&2; exit 1; }
|
|
echo "→ apply-box: applying $BASENAME as the app role (owner = app user)"
|
|
psql "$DBURL" -v ON_ERROR_STOP=1 -f "$REMOTE_TMP"
|
|
rm -f "$REMOTE_TMP"
|
|
echo "✓ apply-box: applied; objects owned by the app role and visible to the app"
|
|
REMOTE
|
|
|
|
echo "✓ apply-box: done. Verify with 'npm run check:schema' or a deploy."
|