-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
41 lines (35 loc) · 1.1 KB
/
Copy pathschema.sql
File metadata and controls
41 lines (35 loc) · 1.1 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
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
username TEXT UNIQUE,
password_hash TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS restaurants (
id INTEGER PRIMARY KEY,
name TEXT UNIQUE,
address TEXT,
user_id INTEGER REFERENCES users,
link TEXT
);
CREATE TABLE IF NOT EXISTS reviews (
id INTEGER PRIMARY KEY,
restaurant_id INTEGER REFERENCES restaurants,
user_id INTEGER REFERENCES users,
rating INTEGER NOT NULL,
comment TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS tags (
id INTEGER PRIMARY KEY,
user_id INTEGER REFERENCES users,
name TEXT UNIQUE
);
CREATE TABLE IF NOT EXISTS restaurant_Tags (
restaurant_id INTEGER REFERENCES restaurants,
tag_id INTEGER REFERENCES tags,
PRIMARY KEY (restaurant_id, tag_id)
);
-- Index on restaurant_id in the reviews table
CREATE INDEX IF NOT EXISTS idx_reviews_restaurant_id ON reviews (restaurant_id);
-- Index on user_id in the reviews table
CREATE INDEX IF NOT EXISTS idx_reviews_user_id ON reviews (user_id);