-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sql
More file actions
executable file
·30 lines (27 loc) · 1.04 KB
/
Copy pathsetup.sql
File metadata and controls
executable file
·30 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- Budget Monitor - Database Setup
-- Run this script in your Supabase SQL Editor (Dashboard > SQL Editor)
CREATE TABLE IF NOT EXISTS categories (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
user_id UUID NOT NULL,
name TEXT NOT NULL,
type TEXT NOT NULL CHECK (type IN ('income', 'expense', 'transfer'))
);
CREATE TABLE IF NOT EXISTS accounts (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
user_id UUID NOT NULL,
name TEXT NOT NULL,
type TEXT NOT NULL CHECK (type IN ('debit', 'credit', 'investment')),
"limit" BIGINT,
CHECK (type <> 'credit' OR "limit" IS NOT NULL)
);
CREATE TABLE IF NOT EXISTS money_transactions (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
user_id UUID NOT NULL,
date TIMESTAMP NOT NULL,
amount INTEGER NOT NULL,
category_id BIGINT REFERENCES categories(id),
account_id BIGINT REFERENCES accounts(id),
description TEXT,
original_description TEXT,
CONSTRAINT unique_transaction UNIQUE (user_id, date, amount, account_id, original_description)
);