-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscheme.sql
More file actions
44 lines (41 loc) · 1.79 KB
/
Copy pathscheme.sql
File metadata and controls
44 lines (41 loc) · 1.79 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
44
CREATE TABLE users (
id BIGINT AUTO_INCREMENT,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
PRIMARY KEY(id)
);
-- Books table
CREATE TABLE books (
id BIGINT AUTO_INCREMENT,
user_id BIGINT NOT NULL,
title VARCHAR(255),
author VARCHAR(255),
total_pages INT,
status ENUM('reading', 'completed') DEFAULT 'reading',
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
PRIMARY KEY(id)
);
-- Progresses table
CREATE TABLE progresses (
id BIGINT AUTO_INCREMENT,
book_id BIGINT NOT NULL,
from_page INT NOT NULL,
until_page INT NOT NULL,
description TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (book_id) REFERENCES books(id) ON DELETE CASCADE,
PRIMARY KEY(id)
);
-- Goals table
CREATE TABLE goals (
id BIGINT AUTO_INCREMENT,
book_id BIGINT NOT NULL,
user_id BIGINT NOT NULL,
name VARCHAR(255),
target_page INT,
status ENUM('finished', 'in-progress', 'expired') DEFAULT 'in-progress',
expired_at DATETIME,
FOREIGN KEY (book_id) REFERENCES books(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
PRIMARY KEY(id)
);