Files
jamo.siu@gmail.com 1e4f028685 refactor(db): switch records layer to Prisma
- Replace hand-written node:sqlite queries with a Prisma client using
  the better-sqlite3 driver adapter
- Version the schema with migrations: baseline table, timestamp
  normalisation, and WAL journal mode
- Store timestamps with an explicit UTC offset so they stop being parsed
  as local time
- Show created/updated times on the edit page, formatted with dayjs
- Move the root redirect into next.config to avoid a prerender error
- Run migrations from the container entrypoint before starting the server

BREAKING CHANGE: DNSMASQ_ADMIN_DB_PATH is replaced by DATABASE_URL, which
must be a Prisma connection URL (file:./data/dnsmasq-admin.db). Existing
database files are migrated in place and need no conversion.
2026-10-12 14:27:03 +08:00

38 lines
1.5 KiB
Plaintext

// dnsmasq-admin — single-table schema mapping the `records` table that shipped with v0.1.0,
// so existing databases keep working untouched.
//
// Keep this file as the single source of truth for the table shape, and keep migrations
// byte-identical to what `prisma migrate diff` produces from it. Hand-editing a migration to
// add something this file cannot express — such as column-level COLLATE NOCASE on `domain`, or
// a CHECK constraint on `type` — leaves Prisma reporting permanent drift, and the next
// `migrate dev` then proposes a DROP TABLE + rebuild migration that silently drops it. Those
// two safeguards therefore live in application code; see
// prisma/migrations/0001_baseline/migration.sql for the details.
//
// The `type` field is a plain String because SQLite has no enum support; the union is enforced
// by lib/validate.ts and by the `RecordType` type in lib/db.ts.
generator client {
provider = "prisma-client"
output = "../lib/generated/prisma"
}
datasource db {
provider = "sqlite"
}
/// Named `DnsRecord` (table `records`) rather than `Record` to avoid colliding with
/// TypeScript's built-in `Record<K, V>` utility type.
model DnsRecord {
id Int @id @default(autoincrement())
domain String @unique
type String
value String
enabled Boolean @default(true)
comment String @default("")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("records")
}