-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.sql
More file actions
30 lines (25 loc) · 864 Bytes
/
db.sql
File metadata and controls
30 lines (25 loc) · 864 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
29
30
CREATE DATABASE ShortUrl;
CREATE TABLE IF NOT EXISTS users (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
role INTEGER DEFAULT 2 NOT NULL
);
CREATE TABLE IF NOT EXISTS password_reset_guids (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
id_user INTEGER,
guid VARCHAR(36) NOT NULL,
expiration_datetime TIMESTAMP NOT NULL,
FOREIGN KEY (id_user) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS urls (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
id_user INTEGER,
original_url TEXT NOT NULL,
short_url TEXT NOT NULL,
clicks INTEGER DEFAULT 0,
last_click TIMESTAMP,
expiration_datetime TIMESTAMP NOT NULL,
FOREIGN KEY (id_user) REFERENCES users(id) ON DELETE CASCADE
);