From 9c1b41bfef8783b7a328bc1027ea5f13fe05ca60 Mon Sep 17 00:00:00 2001 From: Owen Rummage Date: Thu, 20 Aug 2026 17:42:46 -0500 Subject: [PATCH] Add migration to allow the extended zone kind in the database The zones.kind CHECK constraint still only allowed 'forward', 'reverse4' and 'reverse6', so creating an extended zone hit a constraint failure and a 500. Rebuilds the zones table with the widened constraint while preserving row ids so records.zone_id references stay valid. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01V8c76Xr2BycaHHu5N4buqi --- .../migrations/0003_zone_kind_extended.sql | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 internal/database/migrations/0003_zone_kind_extended.sql diff --git a/internal/database/migrations/0003_zone_kind_extended.sql b/internal/database/migrations/0003_zone_kind_extended.sql new file mode 100644 index 0000000..74e384b --- /dev/null +++ b/internal/database/migrations/0003_zone_kind_extended.sql @@ -0,0 +1,39 @@ +-- Adds the "extended" zone kind, which answers authoritatively only for the +-- records it holds and falls through to recursion for everything else. +-- +-- SQLite has no ALTER TABLE ... DROP/ADD CONSTRAINT, so the CHECK constraint +-- on zones.kind is widened by rebuilding the table. The rebuilt table keeps +-- the same name, column order and row ids, so records.zone_id references +-- remain valid without touching the records table at all. + +CREATE TABLE zones_new ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL UNIQUE, + kind TEXT NOT NULL DEFAULT 'forward' + CHECK (kind IN ('forward', 'reverse4', 'reverse6', 'extended')), + description TEXT NOT NULL DEFAULT '', + enabled INTEGER NOT NULL DEFAULT 1, + default_ttl INTEGER NOT NULL DEFAULT 3600, + primary_ns TEXT NOT NULL, + admin_email TEXT NOT NULL, + serial INTEGER NOT NULL DEFAULT 1, + refresh INTEGER NOT NULL DEFAULT 7200, + retry INTEGER NOT NULL DEFAULT 3600, + expire INTEGER NOT NULL DEFAULT 1209600, + minimum INTEGER NOT NULL DEFAULT 3600, + auto_serial INTEGER NOT NULL DEFAULT 1, + created_at INTEGER NOT NULL DEFAULT (unixepoch()), + updated_at INTEGER NOT NULL DEFAULT (unixepoch()) +); + +INSERT INTO zones_new (id, name, kind, description, enabled, default_ttl, primary_ns, + admin_email, serial, refresh, retry, expire, minimum, auto_serial, created_at, updated_at) +SELECT id, name, kind, description, enabled, default_ttl, primary_ns, + admin_email, serial, refresh, retry, expire, minimum, auto_serial, created_at, updated_at +FROM zones; + +DROP TABLE zones; +ALTER TABLE zones_new RENAME TO zones; + +CREATE INDEX idx_zones_enabled ON zones (enabled); +CREATE INDEX idx_zones_kind ON zones (kind);