Files
carvalho-finances/apps/api/internal/migration/sql/004_accounts.sql
T
Mlcavalho1andClaude Sonnet 4.6 9a964423fd feat(#21): contas bancárias e patrimônio consolidado
CRUD de contas (corrente/poupança/investimento/cartão) com saldo calculado
automaticamente. account_id nullable em transactions. Widget patrimônio no
dashboard. Tela /contas. Seletor de conta nas transações manuais.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-05-26 21:34:56 -03:00

15 lines
665 B
SQL

CREATE TABLE IF NOT EXISTS accounts (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
type VARCHAR(20) NOT NULL DEFAULT 'checking'
CHECK (type IN ('checking', 'savings', 'investment', 'credit')),
initial_balance NUMERIC(12, 2) NOT NULL DEFAULT 0,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
ALTER TABLE transactions ADD COLUMN IF NOT EXISTS account_id INTEGER
REFERENCES accounts (id) ON DELETE SET NULL;
INSERT INTO schema_migrations (version) VALUES (4) ON CONFLICT DO NOTHING;