db: Drizzle schemas on domain Postgres schemas, baseline migration, reorg SQL

- pgSchema tables for auth, money, house, ref, games, cs, animaldex, site, meta
  (lists excluded via schemaFilter; runtime list tables are managed by meta.*)
- drizzle/ baseline matches the reorged DB exactly (catalog diff = 0 on rehearsal)
- db/reorg: one-time SQL that moves the flat public schema (rehearsed on a prod copy)
- scripts/db-migrate.ts: migrator with --init to record the baseline and a guard
  against running the baseline on a non-empty, unrecorded database
This commit is contained in:
2026-10-23 22:03:42 +00:00
parent f94e3dc8ac
commit 64fb8df262
29 changed files with 12507 additions and 189 deletions

View File

@@ -1,12 +1,20 @@
import { defineConfig } from 'drizzle-kit';
// Drizzle owns the core schemas only. Deliberately excluded:
// - lists: runtime tables created through meta.create_list() (owned by personal_ddl)
// - legacy: pre-reorg tables kept read-only for rollback
// - energy: owned by ned-collector
// - hardware: not modelled yet
// Migrations run as the schema owner (`personal`), never as the app role.
export default defineConfig({
dialect: 'postgresql',
schema: './src/lib/server/db/schema/index.ts',
out: './drizzle',
schemaFilter: ['auth', 'money', 'house', 'ref', 'games', 'cs', 'animaldex', 'site', 'meta'],
migrations: { schema: 'drizzle', table: '__drizzle_migrations' },
verbose: true,
strict: true,
dbCredentials: {
url: process.env.DB_URL!
url: (process.env.DB_MIGRATE_URL || process.env.DB_URL)!
}
});