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