-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.sql
64 lines (59 loc) · 1.85 KB
/
db.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
DROP TABLE IF EXISTS users CASCADE;
CREATE TABLE users(
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
image TEXT,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
location VARCHAR(255)
);
DROP TABLE IF EXISTS places CASCADE;
CREATE TABLE places(
id VARCHAR(255) PRIMARY KEY,
name VARCHAR(255),
lat NUMERIC(14, 11) NOT NULL,
lng NUMERIC(14, 11) NOT NULL,
tags TEXT [],
is_natural BOOLEAN NOT NULL,
radius FLOAT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
DROP TABLE IF EXISTS routes CASCADE;
CREATE TABLE routes(
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
user_id INT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
places TEXT [] NOT NULL,
duration INT NOT NULL,
distance FLOAT NOT NULL,
thumbnail TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
DROP TABLE IF EXISTS images CASCADE;
CREATE TABLE images(
image TEXT NOT NULL UNIQUE,
title TEXT,
lat NUMERIC(14, 11) NOT NULL,
lng NUMERIC(14, 11) NOT NULL,
place_id VARCHAR(255) NOT NULL REFERENCES places(id) ON DELETE CASCADE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(image, place_id)
);
DROP TABLE IF EXISTS reviews CASCADE;
CREATE TABLE reviews(
id SERIAL PRIMARY KEY,
place_id VARCHAR(255) REFERENCES places(id) ON DELETE CASCADE,
route_id INT REFERENCES routes(id) ON DELETE CASCADE,
text TEXT NOT NULL,
rating INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT one_not_null CHECK (num_nonnulls(place_id, route_id) = 1)
);
DROP TABLE IF EXISTS reset_codes CASCADE;
CREATE TABLE reset_codes(
id SERIAL PRIMARY KEY,
email VARCHAR NOT NULL,
code VARCHAR NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);