CREATE TABLE prefix_snapshot (
    id            TEXT NOT NULL PRIMARY KEY,
    content_hash  TEXT NOT NULL UNIQUE,
    created_at    TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
);

CREATE TABLE prefix_snapshot_row (
    snapshot_id   TEXT NOT NULL REFERENCES prefix_snapshot (id) ON DELETE CASCADE,
    ord           INTEGER NOT NULL,
    prefix        TEXT NOT NULL,
    community_id  TEXT,
    source        TEXT NOT NULL DEFAULT '',
    PRIMARY KEY (snapshot_id, ord)
);

CREATE INDEX idx_prefix_snapshot_row_snapshot ON prefix_snapshot_row (snapshot_id);

ALTER TABLE config_revision ADD COLUMN prefix_snapshot_id TEXT REFERENCES prefix_snapshot (id) ON DELETE RESTRICT;
