Loki moves from Auth.js to @bitbaum/accountkit one reversible step at a time, as evig, kivvi, petvity and surf-your-life do. Nothing changes while AUTH_RUNTIME is unset. - Migration 0130: AccountKit's tables under `auth_`, and the mirror functions: users <-> auth_users, and AccountKit's OrangeCat token set into Loki's `accounts`, where publish, promote and the wallet read it. - scripts/db/accountkit-import.sql + a rollback-only rehearsal: ids, Loki's own scrypt hashes (read through AccountKit 0.17.0's legacyPassword), verification, OrangeCat links, a placeholder address for people with none; collisions, drift and a live shared runtime refused. - src/lib/auth/shared/: the runtime, the session re-read from `users` on every request, and a bridge for next-auth/react: email, the invite's user-password and the owner key (stored hash only), OrangeCat sign-in or link, and the studio's server signIn by redirect. GitHub, Google and X are not offered on this runtime (getEnabledAuthProviders knows it). - src/lib/auth/bootstrap.ts: onboarding heal and personal org, now one function both runtimes call. - The proxy reads the shared session and asks the same authorized(). - /api/me/password keeps the caller's shared session. - scripts/test/accountkit-journeys.ts joins `test:db` (16 journeys and the rehearsal on CI's Postgres). docs/architecture/accountkit-migration.md records what blocks the switch, chiefly GitHub/Google sign-in and the GitHub repository token. Claude-Session: https://claude.ai/code/session_019MDtmud6zcK4rStBGmYSML Co-authored-by: Claude <noreply@anthropic.com>
scripts/db — Loki database toolkit
Portable pg_dump/psql tooling for Loki's PostgreSQL database, plus
the historical runbooks from the one-time migration onto the self-hosted box.
Where the database lives now
Loki's Postgres runs self-hosted on the Hetzner bitbaum box
(167.233.22.31), Postgres 17 on the host, one role/database per app. The
app reads its connection string from DATABASE_URL. There is no managed-DB
vendor in the loop — the migration off Neon (Loki) and managed Supabase
(OrangeCat) completed 2026-06-12. See docs/infrastructure/hetzner-migration.md
for the full box layout and that migration's history.
Deploys go through scripts/deploy-hetzner.sh (build → rsync → restart the
loki-app service). Self-hosted Supabase stays at supabase.orangecat.ch
for OrangeCat's auth/storage — that is separate from Loki's plain Postgres.
Files
| File | Purpose |
|---|---|
dump.sh |
Portable pg_dump of Loki to a .sql.gz file. DATABASE_URL=... (or .env.local). |
restore.sh |
Restore a .sql.gz dump into a target DB. |
restore-to-target.sh |
psql a plain-SQL dump into a target, verifying row counts against a manifest; halts on mismatch. |
sync-user-data.sh |
Copy user-owned rows between two databases (schema must already exist on the target). |
bootstrap-migration-ledger.ts |
Seed drizzle.__drizzle_migrations when schema arrived via push (one-time). |
audit-duplicate-projects.ts |
List case-insensitive duplicate project entities per user. |
merge-duplicate-projects.ts |
Merge duplicate project entities (dry run by default; --apply to write). Run after imports that created botsmann + Botsmann pairs. |
retire-stale-projects.ts |
Explicit merge/delete list for renamed or obsolete projects (dry run by default; --apply). |
link-prod-runtime.ts |
Upsert user_projects.dir_path for entities missing Fleet Runner links. |
list-projects.ts |
Inventory helper — entity attr/goal counts + runtime rows. |
SETUP_HETZNER.md |
Provision + install + secure a Hetzner box for Postgres 17. |
BOTH_PRODUCTS_ONE_HOST.md |
Layer two databases on one Postgres instance — role + pg_hba setup, capacity math, "when to split" triggers. |
Backup + restore (routine)
# Back up production
DATABASE_URL="$PROD_DATABASE_URL" scripts/db/dump.sh loki-$(date +%F).sql.gz
# Restore into a fresh target (e.g. a new box, or local)
DATABASE_URL="$TARGET_DATABASE_URL" scripts/db/restore.sh loki-<date>.sql.gz
The box also runs a nightly pg_dump cron with 14-day retention
(/opt/backups/nightly/); see the hetzner-migration doc.
Moving the database to a new host (if you ever do)
Switching Postgres hosts is a dump/restore + config job, not a code rewrite —
the app only needs DATABASE_URL repointed.
- Dump source:
DATABASE_URL="$OLD_URL" scripts/db/dump.sh source.sql.gz - Stand up target: follow
SETUP_HETZNER.mdsections 1–5 (Postgres 17, role + database, firewall). You end with a workingpostgresql://loki:...@<host>:5432/loki?sslmode=requireURL. - Restore + verify:
The script halts if any table row count mismatches the source manifest.
TARGET_DATABASE_URL="$NEW_URL" DUMP_FILE="source.sql" scripts/db/restore-to-target.sh - Repoint the app: set
DATABASE_URL(andDATABASE_POOL_URLif used) in the app's env on the box, then redeploy withscripts/deploy-hetzner.sh. - Smoke:
Browse
curl -s https://loki.orangecat.ch/api/health # → 200 curl -s -o /dev/null -w "%{http_code}\n" https://loki.orangecat.ch/ # → 200/control,/settings,/system— should load without "Something went wrong."
Why not Drizzle migrations for data?
drizzle-kit syncs schema; data migration is not its job. pg_dump/psql is
the well-trodden path for "move this database intact," and the SQL output is
auditable in a way binary formats aren't.