adicionado comentários
This commit is contained in:
parent
e8ca410b94
commit
e796b29e1d
8 changed files with 875 additions and 13 deletions
|
|
@ -96,6 +96,55 @@ func EnsurePgcrypto(ctx context.Context, pool *pgxpool.Pool) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// EnsurePainelTables cria as tabelas globais usadas pelo painel.
|
||||
//
|
||||
// Motivação:
|
||||
// - as respostas ficam em tabelas dinâmicas por produto (nps_{produto})
|
||||
// - precisamos de um lugar único para registrar auditoria de análise (pendente/concluída)
|
||||
// e comentários internos do painel
|
||||
//
|
||||
// Importante:
|
||||
// - tudo é criado de forma defensiva (IF NOT EXISTS)
|
||||
// - SQL sempre parametrizado (aqui não há identificadores dinâmicos)
|
||||
func EnsurePainelTables(ctx context.Context, pool *pgxpool.Pool) error {
|
||||
// Status de análise por (produto + resposta_id)
|
||||
if _, err := pool.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS painel_resposta_status (
|
||||
produto text NOT NULL,
|
||||
resposta_id text NOT NULL,
|
||||
status text NOT NULL CHECK (status IN ('pendente','concluida')),
|
||||
concluida_em timestamptz NULL,
|
||||
atualizado_em timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (produto, resposta_id)
|
||||
)`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Comentários internos por resposta.
|
||||
if _, err := pool.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS painel_resposta_comentario (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
produto text NOT NULL,
|
||||
resposta_id text NOT NULL,
|
||||
pessoa_nome text NOT NULL,
|
||||
sessao_id uuid NOT NULL,
|
||||
comentario text NOT NULL,
|
||||
criado_em timestamptz NOT NULL DEFAULT now(),
|
||||
atualizado_em timestamptz NOT NULL DEFAULT now()
|
||||
)`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := pool.Exec(ctx, `
|
||||
CREATE INDEX IF NOT EXISTS idx_painel_resp_comentario
|
||||
ON painel_resposta_comentario (produto, resposta_id, criado_em ASC)
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnsureNPSTable cria a tabela por produto + índices se não existirem.
|
||||
// Importante: tableName deve ser criada a partir de um produto normalizado.
|
||||
func EnsureNPSTable(ctx context.Context, pool *pgxpool.Pool, tableName string) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue