-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
43 lines (40 loc) · 1.17 KB
/
Copy pathschema.sql
File metadata and controls
43 lines (40 loc) · 1.17 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
31
32
33
34
35
36
37
38
39
40
41
42
43
-- Users table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
role VARCHAR(50) DEFAULT 'user',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Accounts table
CREATE TABLE accounts (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
account_number VARCHAR(20) UNIQUE NOT NULL,
balance DECIMAL(15,2) DEFAULT 0,
type VARCHAR(50) DEFAULT 'savings',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Cards table
CREATE TABLE cards (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
card_number VARCHAR(16) NOT NULL,
card_type VARCHAR(50) NOT NULL,
expiry_date DATE NOT NULL,
cvv VARCHAR(3) NOT NULL,
status VARCHAR(50) DEFAULT 'active',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Transactions table
CREATE TABLE transactions (
id SERIAL PRIMARY KEY,
from_account_id INTEGER REFERENCES accounts(id),
to_account_id INTEGER REFERENCES accounts(id),
amount DECIMAL(15,2) NOT NULL,
type VARCHAR(50) NOT NULL,
status VARCHAR(50) DEFAULT 'pending',
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);