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);