Primeiro commit

This commit is contained in:
2025-10-14 14:04:17 -03:00
commit 33d8645eb4
109 changed files with 55424 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
-- Adicionar coluna id_cliente na tabela clientes (numérico)
ALTER TABLE clientes ADD COLUMN IF NOT EXISTS id_cliente VARCHAR(10);
-- Criar índice para melhor performance
CREATE INDEX IF NOT EXISTS idx_clientes_id_cliente ON clientes(id_cliente);
-- Gerar IDs numéricos sequenciais para clientes existentes (se houver)
WITH numbered_clients AS (
SELECT id, ROW_NUMBER() OVER (ORDER BY created_at) as row_num
FROM clientes
WHERE id_cliente IS NULL
)
UPDATE clientes
SET id_cliente = numbered_clients.row_num::TEXT
FROM numbered_clients
WHERE clientes.id = numbered_clients.id;
-- Tornar a coluna NOT NULL após popular os dados existentes
ALTER TABLE clientes ALTER COLUMN id_cliente SET NOT NULL;
-- Adicionar constraint de unicidade
ALTER TABLE clientes ADD CONSTRAINT unique_id_cliente UNIQUE (id_cliente);