Como funciona?
Ao conectar seu projeto no Supabase, todas as transações passam a ser salvas na nuvem com sincronização em tempo real entre os celulares.
Script SQL para o Supabase:
-- 1. Tabela de Transações (Receitas e Despesas)
create table if not exists transactions (
id text primary key,
type text not null,
description text not null,
amount numeric not null,
category text not null,
date date not null,
created_at timestamp with time zone default timezone('utc'::text, now())
);
-- 1.1 Colunas essenciais 'user' e 'status'
alter table transactions add column if not exists "user" text default 'Luiz';
alter table transactions add column if not exists status text default 'realized';
alter table transactions enable row level security;
do $$
begin
if not exists (select 1 from pg_policies where tablename = 'transactions' and policyname = 'Acesso público transactions') then
create policy "Acesso público transactions" on transactions for all using (true) with check (true);
end if;
end $$;
do $$
begin
if not exists (
select 1 from pg_publication_tables
where pubname = 'supabase_realtime' and schemaname = 'public' and tablename = 'transactions'
) then
alter publication supabase_realtime add table transactions;
end if;
exception when others then null;
end $$;
-- 2. Tabela de Categorias (Sincronização entre PC e Celulares)
create table if not exists categories (
id text primary key,
name text not null,
type text not null,
created_at timestamp with time zone default timezone('utc'::text, now())
);
alter table categories enable row level security;
do $$
begin
if not exists (select 1 from pg_policies where tablename = 'categories' and policyname = 'Acesso público categories') then
create policy "Acesso público categories" on categories for all using (true) with check (true);
end if;
end $$;
do $$
begin
if not exists (
select 1 from pg_publication_tables
where pubname = 'supabase_realtime' and schemaname = 'public' and tablename = 'categories'
) then
alter publication supabase_realtime add table categories;
end if;
exception when others then null;
end $$;
-- 3. Limpeza opcional prévia de categorias obsoletas:
delete from categories where id not in (
'rec_salario', 'rec_honorarios', 'rec_saque_poupanca', 'rec_rendimentos', 'rec_reembolsos',
'desp_moradia', 'desp_alimentacao', 'desp_transporte', 'desp_filhos', 'desp_saude',
'desp_lazer', 'desp_trabalho', 'desp_investimentos', 'desp_taxas'
);
-- 4. Inserir/Atualizar as 5 RECEITAS e 9 DESPESAS ENXUTAS
insert into categories (id, name, type) values
-- RECEITAS (5 Categorias Enxutas)
('rec_salario', '💼 Salário / Renda Fixa', 'income'),
('rec_honorarios', '📑 Honorários & Serviços Extras', 'income'),
('rec_saque_poupanca', '💰 Saque Poupança / Reserva', 'income'),
('rec_rendimentos', '📈 Rendimentos & Investimentos', 'income'),
('rec_reembolsos', '🔄 Reembolsos & Outras Entradas', 'income'),
-- DESPESAS (9 Categorias Enxutas)
('desp_moradia', '🏠 Moradia & Contas Básicas', 'expense'),
('desp_alimentacao', '🛒 Alimentação', 'expense'),
('desp_transporte', '🚗 Transporte & Veículo', 'expense'),
('desp_filhos', '👶 Filhos & Família', 'expense'),
('desp_saude', '🩺 Saúde & Bem-Estar', 'expense'),
('desp_lazer', '🎬 Lazer & Estilo de Vida', 'expense'),
('desp_trabalho', '💼 Trabalho & Profissional', 'expense'),
('desp_investimentos', '📈 Investimentos & Futuro', 'expense'),
('desp_taxas', '🏦 Taxas & Outros', 'expense')
on conflict (id) do update set name = excluded.name, type = excluded.type;