-- Per-module materialized prefix cache to avoid re-fetching external sources on every tenant render.
CREATE TABLE module_prefix_snapshot (
    tenant_id      UUID NOT NULL REFERENCES tenant (id) ON DELETE CASCADE,
    module_id      UUID NOT NULL REFERENCES module (id) ON DELETE CASCADE,
    input_hash     TEXT NOT NULL,
    collected_at   TIMESTAMPTZ NOT NULL DEFAULT now(),
    prefixes_json  JSONB NOT NULL DEFAULT '[]',
    PRIMARY KEY (tenant_id, module_id)
);

CREATE INDEX idx_module_prefix_snapshot_collected ON module_prefix_snapshot (collected_at);
