-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.sql
More file actions
39 lines (36 loc) · 1.4 KB
/
Copy pathdb.sql
File metadata and controls
39 lines (36 loc) · 1.4 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
-- Users table
CREATE TABLE Users (
id SERIAL PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
role VARCHAR(50) CHECK (role IN ('admin', 'user')) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Accounts table
CREATE TABLE Accounts (
account_number SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES Users(id) ON DELETE CASCADE,
balance DECIMAL(15, 2) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Transactions table
CREATE TABLE Transactions (
id SERIAL PRIMARY KEY,
account_number INTEGER REFERENCES Accounts(account_number) ON DELETE CASCADE,
from_account_number INTEGER REFERENCES Accounts(account_number) ON DELETE CASCADE,
to_account_number INTEGER REFERENCES Accounts(account_number) ON DELETE CASCADE,
amount DECIMAL(15, 2) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- DatabaseLogs table
CREATE TABLE DatabaseLogs (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES Users(id) ON DELETE CASCADE,
request VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);