PASSO 3 — Criar as tabelas via SQL
No menu lateral, clique em SQL Editor, cole o SQL abaixo e clique Run:
-- NOVA INSTALAÇÃO (use este SQL se estiver criando do zero)
create table if not exists coilsdb (coil text not null, navio text not null default '', bl text not null default '', armazem text, cliente text, viagem text, produto text, pesob text, pesol text, primary key (coil, navio, bl));
create table if not exists records (id bigint primary key, coil text, data text, periodo text, bl text, navio text, veiculo text, motorista text, cliente text, viagem text, produto text, pesob text, pesol text, armazem text, obs text, "registradoEm" text, "registradoPor" text);
create table if not exists expedicoes (id bigint primary key, coil text, data text, periodo text, bl text, navio text, veiculo text, motorista text, cliente text, viagem text, produto text, pesob text, pesol text, armazem text, obs text, "registradoEm" text, "registradoPor" text);
create table if not exists users (id text primary key, nome text, "user" text, pass text, role text, perms text, email text);
create table if not exists navios (nome text primary key);
create table if not exists fat_config (chave text primary key, valor text);
alter table coilsdb enable row level security;
alter table records enable row level security;
alter table expedicoes enable row level security;
alter table users enable row level security;
alter table navios enable row level security;
alter table fat_config enable row level security;
create policy "allow all" on coilsdb for all using (true) with check (true);
create policy "allow all" on records for all using (true) with check (true);
create policy "allow all" on expedicoes for all using (true) with check (true);
create policy "allow all" on users for all using (true) with check (true);
create policy "allow all" on navios for all using (true) with check (true);
create policy "allow all" on fat_config for all using (true) with check (true);
-- Se as tabelas já existem, rode estas linhas para adicionar as novas colunas:
alter table records add column if not exists "registradoPor" text;
alter table expedicoes add column if not exists "registradoPor" text;
alter table users add column if not exists email text;
-- ⚠ MIGRAÇÃO — rode apenas se coilsdb já existe com PK antiga (coil):
-- (permite mesmo coil number em navios/BLs diferentes)
-- ALTER TABLE coilsdb DROP CONSTRAINT coilsdb_pkey;
-- ALTER TABLE coilsdb ADD PRIMARY KEY (coil, navio, bl);
-- UPDATE coilsdb SET navio='' WHERE navio IS NULL;
-- UPDATE coilsdb SET bl='' WHERE bl IS NULL;