31 lines
1.2 KiB
SQL
31 lines
1.2 KiB
SQL
-- e-li.nps base migration (run once)
|
|
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
|
|
|
-- Example product table (optional; app auto-creates per product):
|
|
-- CREATE TABLE IF NOT EXISTS nps_exemplo (
|
|
-- id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
-- inquilino_codigo text NOT NULL,
|
|
-- inquilino_nome text NOT NULL,
|
|
-- usuario_codigo text,
|
|
-- usuario_nome text NOT NULL,
|
|
-- usuario_email text,
|
|
-- usuario_telefone text,
|
|
-- status text NOT NULL CHECK (status IN ('pedido','respondido')),
|
|
-- pedido_criado_em timestamptz NOT NULL DEFAULT now(),
|
|
-- respondido_em timestamptz NULL,
|
|
-- atualizado_em timestamptz NOT NULL DEFAULT now(),
|
|
-- nota int NULL CHECK (nota BETWEEN 1 AND 10),
|
|
-- justificativa text NULL,
|
|
-- valida bool NOT NULL DEFAULT true,
|
|
-- origem text NOT NULL DEFAULT 'widget_iframe',
|
|
-- user_agent text NULL,
|
|
-- ip_real text NULL
|
|
-- );
|
|
--
|
|
-- CREATE INDEX IF NOT EXISTS idx_nps_resp_recente_exemplo
|
|
-- ON nps_exemplo (inquilino_codigo, usuario_codigo, respondido_em DESC)
|
|
-- WHERE status='respondido' AND valida=true;
|
|
--
|
|
-- CREATE INDEX IF NOT EXISTS idx_nps_pedido_aberto_exemplo
|
|
-- ON nps_exemplo (inquilino_codigo, usuario_codigo, pedido_criado_em DESC)
|
|
-- WHERE status='pedido';
|