forked from aionate0812/bundle_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.sql
187 lines (152 loc) · 3.68 KB
/
seed.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS trips;
DROP TABLE IF EXISTS bag_types;
DROP TABLE IF EXISTS bags;
DROP TABLE IF EXISTS flags;
DROP TABLE IF EXISTS categories;
DROP TABLE IF EXISTS items;
DROP TABLE IF EXISTS itinerary;
DROP TABLE IF EXISTS itinerary_types;
DROP TABLE IF EXISTS todolist;
DROP TABLE IF EXISTS todos;
CREATE TABLE users
(
id SERIAL PRIMARY KEY,
uid VARCHAR UNIQUE NOT NULL,
username VARCHAR(50) NULL,
email VARCHAR(255) UNIQUE NOT NULL
);
CREATE TABLE trips
(
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
country VARCHAR(100) NULL,
city VARCHAR(100) NULL,
departure_date DATE NULL,
return_date DATE NULL,
user_id INT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE bag_types
(
id SERIAL PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE bags
(
id SERIAL PRIMARY KEY,
trip_id INT NOT NULL,
type_id INT NOT NULL,
FOREIGN KEY (trip_id) REFERENCES trips(id),
FOREIGN KEY (type_id) REFERENCES bag_types(id)
);
CREATE TABLE flags
(
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
description VARCHAR(255) NOT NULL
);
CREATE TABLE categories
(
id SERIAL PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE items
(
id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
packed BOOLEAN NOT NULL,
image VARCHAR(255) NULL,
quantity INT NOT NULL,
important BOOLEAN,
flag BOOLEAN NULL,
bag_id INT NOT NULL,
shop BOOLEAN NULL,
category_id INT NOT NULL,
FOREIGN KEY (bag_id) REFERENCES bags(id),
FOREIGN KEY (category_id) REFERENCES categories(id)
);
CREATE TABLE itinerary_types
(
id SERIAL PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE itinerary
(
id SERIAL PRIMARY KEY,
name VARCHAR(50),
address VARCHAR(255),
phone_number VARCHAR(20),
note VARCHAR (255),
trip_id INT NOT NULL,
type_id INT NOT NULL,
FOREIGN KEY (type_id) REFERENCES itinerary_types(id),
FOREIGN KEY (trip_id) REFERENCES trips(id)
);
CREATE TABLE todolist
(
id SERIAL PRIMARY KEY,
name VARCHAR(50),
list_type VARCHAR(20) NOT NULL,
trip_id INT NOT NULL,
FOREIGN KEY (trip_id) REFERENCES trips(id)
);
CREATE TABLE todos
(
id SERIAL PRIMARY KEY,
task_name VARCHAR(75),
complete BOOLEAN NOT NULL,
item_id INT NULL,
todolist_id INT NOT NULL,
FOREIGN KEY (todolist_id) REFERENCES todolist(id)
);
-- INSERT BAG TYPES
INSERT INTO bag_types (name)
VALUES ('personal');
INSERT INTO bag_types (name)
VALUES ('carry-on');
INSERT INTO bag_types (name)
VALUES ('checked');
-- INSERT CATEGORIES
INSERT INTO categories (name)
VALUES ('clothing');
INSERT INTO categories (name)
VALUES ('accessories');
INSERT INTO categories (name)
VALUES ('electronics');
INSERT INTO categories (name)
VALUES ('personal');
INSERT INTO categories (name)
VALUES ('documents');
INSERT INTO categories (name)
VALUES ('first-aid');
INSERT INTO categories (name)
VALUES ('essentials');
INSERT INTO categories (name)
VALUES ('children');
INSERT INTO categories (name)
VALUES ('misc');
-- INSERT ITINERARY TYPES
INSERT INTO itinerary_types (name)
VALUES ('hotel');
INSERT INTO itinerary_types (name)
VALUES ('car rental');
INSERT INTO itinerary_types (name)
VALUES ('restaurant');
INSERT INTO itinerary_types (name)
VALUES ('vacation rental');
INSERT INTO itinerary_types (name)
VALUES ('flight');
INSERT INTO itinerary_types (name)
VALUES ('cruise');
INSERT INTO itinerary_types (name)
VALUES ('shopping');
INSERT INTO itinerary_types (name)
VALUES ('tour');
INSERT INTO itinerary_types (name)
VALUES ('activity');
INSERT INTO itinerary_types (name)
VALUES ('entertainment');
INSERT INTO itinerary_types (name)
VALUES ('event');
SELECT * FROM todolist;