-- migrate:up -- Templates de respuestas con variantes para evitar repetición. -- Filosofía: cada slot semántico (ej. cart.ask_more) tiene N variantes; -- el código rota entre ellas excluyendo las recientemente usadas. CREATE TABLE reply_templates ( id SERIAL PRIMARY KEY, tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE, template_key VARCHAR(80) NOT NULL, variant INTEGER NOT NULL DEFAULT 1, content TEXT NOT NULL, weight INTEGER NOT NULL DEFAULT 1, is_active BOOLEAN NOT NULL DEFAULT true, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), CONSTRAINT uq_reply_variant UNIQUE(tenant_id, template_key, variant) ); CREATE INDEX idx_reply_active ON reply_templates(tenant_id, template_key) WHERE is_active = true; -- migrate:down DROP INDEX IF EXISTS idx_reply_active; DROP TABLE IF EXISTS reply_templates;