-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
28 lines (26 loc) · 834 Bytes
/
Copy pathschema.sql
File metadata and controls
28 lines (26 loc) · 834 Bytes
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
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL,
hash TEXT NOT NULL,
currency TEXT DEFAULT 'USD'
);
CREATE TABLE IF NOT EXISTS transactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
amount DECIMAL(10,2) NOT NULL,
category TEXT NOT NULL,
description TEXT,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
type TEXT CHECK(type IN ('income', 'expense')),
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE IF NOT EXISTS budgets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
category TEXT NOT NULL,
amount DECIMAL(10,2) NOT NULL,
month INTEGER NOT NULL,
year INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id),
UNIQUE(user_id, category, month, year)
);