-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdatabase.sql
34 lines (32 loc) · 1.15 KB
/
database.sql
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
CREATE TABLE IF NOT EXISTS users(
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
email varchar(255) NOT NULL,
password varchar(255) NOT NULL,
age tinyint(3) unsigned NOT NULL,
country varchar(255) NOT NULL,
social_media_url varchar(255) NOT NULL,
created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP(),
updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY(id),
UNIQUE KEY(email)
);
CREATE TABLE IF NOT EXISTS transactions(
id bigint(20) NOT NULL AUTO_INCREMENT,
description varchar(255) NOT NULL,
amount decimal(10,2) NOT NULL,
date datetime NOT NULL,
created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP(),
updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP(),
user_id bigint(20) unsigned NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(user_id) REFERENCES users(id)
);
CREATE TABLE IF NOT EXISTS receipts(
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
original_filename varchar(255) NOT NULL,
storage_filename varchar(255) NOT NULL,
media_type varchar(255) NOT NULL,
transaction_id bigint(20) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY(transaction_id) REFERENCES transactions (id) ON DELETE CASCADE
);