This repository was archived by the owner on Nov 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatetable.sql
More file actions
91 lines (82 loc) · 2.51 KB
/
createtable.sql
File metadata and controls
91 lines (82 loc) · 2.51 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
-- Enable PostGIS extension
CREATE EXTENSION IF NOT EXISTS postgis;
-- Users Table
CREATE TABLE users (
user_id SERIAL PRIMARY KEY,
nickname VARCHAR(255) NOT NULL,
user_flag BOOLEAN NOT NULL DEFAULT false,
icon TEXT NOT NULL DEFAULT 'img/user/default.png',
-- location GEOMETRY(Point, 4326) NOT NULL,
-- auth_id UUID REFERENCES auth.users (id) ON DELETE CASCADE,
auth_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE
-- error_count INTEGER NOT NULL DEFAULT 0,
-- last_error_timestamp TIMESTAMP,
-- notification_frequency INTEGER NOT NULL,
-- FOREIGN KEY (auth_id) REFERENCES auth.users(id)
);
-- Messages Table
CREATE TABLE messages (
message_id SERIAL PRIMARY KEY,
address VARCHAR(255),
message_text TEXT,
recommended_place VARCHAR(255),
location GEOMETRY,
category VARCHAR(50),
post_timestamp TIMESTAMP,
user_id INTEGER,
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
-- Favorites Table
CREATE TABLE favorites (
message_id INTEGER,
user_id INTEGER,
registration_date TIMESTAMP,
PRIMARY KEY (message_id, user_id),
FOREIGN KEY (message_id) REFERENCES messages(message_id),
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
-- Bookmarks Table
CREATE TABLE bookmarks (
message_id INTEGER,
user_id INTEGER,
registration_date TIMESTAMP,
PRIMARY KEY (message_id, user_id),
FOREIGN KEY (message_id) REFERENCES messages(message_id),
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
-- Stores Table
CREATE TABLE stores (
store_id SERIAL PRIMARY KEY,
store_name VARCHAR(255),
location GEOMETRY,
postal_code VARCHAR(10),
address VARCHAR(255)
);
-- Store Details Table
CREATE TABLE store_details (
store_id INTEGER,
user_id INTEGER,
PRIMARY KEY (store_id, user_id),
FOREIGN KEY (store_id) REFERENCES stores(store_id),
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
-- Coupons Table
CREATE TABLE coupons (
coupon_id SERIAL PRIMARY KEY,
coupon_name VARCHAR(255) NOT NULL,
coupon_image TEXT NOT NULL DEFAULT 'img/coupon/default.png',
start_date TIMESTAMP NOT NULL,
end_date TIMESTAMP NOT NULL,
store_id INTEGER,
FOREIGN KEY (store_id) REFERENCES stores(store_id)
);
-- Encounters Table
CREATE TABLE encounters (
encounter_id SERIAL PRIMARY KEY,
user1_id INTEGER,
user2_id INTEGER,
encounter_date TIMESTAMP,
location GEOMETRY,
FOREIGN KEY (user1_id) REFERENCES users(user_id),
FOREIGN KEY (user2_id) REFERENCES users(user_id)
);