SQL — Atualização do Schema (rode no Supabase se já tinha banco)
alter table cotacoes add column if not exists chatwoot_conv_id integer;
alter table cotacoes add column if not exists chatwoot_conv_url text;
alter table cotacoes add column if not exists resposta_texto text;
alter table cotacoes add column if not exists respondeu_em timestamptz;
alter table cotacoes add column if not exists selecionada boolean default false;
alter table cotacoes add column if not exists total_manual numeric;
alter table cotacoes add column if not exists prazo_dias integer;
SQL — Tabela SINAPI (opcional — importe os dados da Caixa)
create table if not exists sinapi_precos (
id serial primary key,
codigo text,
nome_curto text not null,
unidade text,
preco_unitario numeric,
estado text,
mes_ref text,
updated_at timestamptz default now()
);
create index on sinapi_precos using gin(to_tsvector('portuguese', nome_curto));
-- Após criar: importe planilha SINAPI da Caixa (https://www.caixa.gov.br/site/paginas/downloads.aspx)
Schema Completo (novo banco)
create table obras (
id uuid default gen_random_uuid() primary key,
nome text not null, cidade text, cep text,
endereco text, tipo text, raio integer default 100,
area numeric, obs text,
criada_em timestamptz default now()
);
create table materiais (
id uuid default gen_random_uuid() primary key,
obra_id uuid references obras(id) on delete cascade,
nome text not null, categoria text,
quantidade numeric, unidade text,
criada_em timestamptz default now()
);
create table cotacoes (
id uuid default gen_random_uuid() primary key,
obra_id uuid references obras(id) on delete cascade,
fornecedor jsonb not null,
chatwoot_conv_id integer,
chatwoot_conv_url text,
resposta_texto text,
respondeu_em timestamptz,
selecionada boolean default false,
total_manual numeric,
prazo_dias integer,
status text default 'enviando',
criada_em timestamptz default now()
);
alter table obras enable row level security;
alter table materiais enable row level security;
alter table cotacoes enable row level security;
create policy "pub obras" on obras for all using (true) with check (true);
create policy "pub materiais" on materiais for all using (true) with check (true);
create policy "pub cotacoes" on cotacoes for all using (true) with check (true);