-- Per-DID database schema

CREATE TABLE IF NOT EXISTS records (
    rkey        TEXT PRIMARY KEY,
    domain      TEXT NOT NULL,
    record_type TEXT NOT NULL,
    data        TEXT NOT NULL,   -- JSON-encoded full DnsRecord (domain + ttl + record)
    created_at  INTEGER NOT NULL,
    updated_at  INTEGER NOT NULL
);

CREATE TABLE IF NOT EXISTS zones (
    rkey        TEXT PRIMARY KEY,
    domain      TEXT NOT NULL UNIQUE,
    created_at  INTEGER NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_records_domain
    ON records(domain);

CREATE INDEX IF NOT EXISTS idx_records_domain_type
    ON records(domain, record_type);
