design: schema_creation.sql

File schema_creation.sql, 6.5 KB (added by 231175, 2 days ago)
Line 
1drop table if exists _user;
2
3create table _user (
4 id BIGSERIAL primary key,
5 name VARCHAR(255),
6 email VARCHAR(255) not null unique,
7 login_provider VARCHAR(50),
8 password_hash VARCHAR(255) not null,
9 verified BOOLEAN not null,
10 profile_complete BOOLEAN not null,
11 used_free_consultation BOOLEAN not null,
12 company_size VARCHAR(50),
13 work_position VARCHAR(255),
14 points INTEGER
15);
16
17drop table if exists meeting_email_reminder;
18
19create table meeting_email_reminder (
20 id BIGSERIAL primary key,
21 meeting_at TIMESTAMP not null,
22 scheduled_at TIMESTAMP not null,
23 sent BOOLEAN not null,
24 meeting_link TEXT not null,
25 user_id BIGINT not null,
26 foreign key (user_id) references _user(id) on
27delete
28 cascade
29);
30
31drop table if exists user_favorite_course_ids;
32
33create table user_favorite_course_ids (
34 user_id BIGINT not null,
35 favorite_course_ids BIGINT not null,
36 primary key (user_id,
37favorite_course_ids),
38 foreign key (user_id) references _user(id) on
39delete
40 cascade
41);
42
43drop table if exists expert;
44
45create table expert (
46 id BIGSERIAL primary key,
47 name VARCHAR(255),
48 email VARCHAR(255) not null unique,
49 login_provider VARCHAR(50),
50 password_hash VARCHAR(255) not null
51);
52
53drop table if exists course;
54
55create table course (
56 id BIGSERIAL primary key,
57 image_url TEXT not null,
58 color VARCHAR(255),
59 difficulty VARCHAR(255) not null,
60 duration_minutes INT not null,
61 price DOUBLE precision not null
62);
63
64drop table if exists expert_course;
65
66create table expert_course (
67 course_id BIGINT not null,
68 expert_id BIGINT not null,
69 primary key (expert_id,
70course_id),
71 foreign key (expert_id) references expert(id) on
72delete
73 cascade,
74 foreign key (course_id) references course(id) on
75 delete
76 cascade
77);
78
79drop table if exists course_version;
80
81create table course_version (
82 id BIGSERIAL primary key,
83 version_number INT not null,
84 creation_date DATE default CURRENT_DATE not null,
85 active BOOLEAN not null,
86 course_id BIGINT not null,
87 foreign key (course_id) references course(id) on
88delete
89 cascade
90);
91
92drop table if exists enrollment;
93
94create table enrollment (
95 id BIGSERIAL primary key,
96 enrollment_status VARCHAR(255),
97 purchase_date DATE,
98 activation_date DATE default CURRENT_DATE,
99 completion_date DATE,
100 course_version_id BIGINT not null,
101 user_id BIGINT not null,
102 foreign key (user_id) references _user(id),
103 foreign key (course_version_id) references course_version(id)
104);
105
106drop table if exists payment;
107
108create table payment (
109 id BIGSERIAL primary key,
110 amount DOUBLE precision not null,
111 payment_date DATE default CURRENT_DATE not null,
112 payment_method VARCHAR(255) not null,
113 payment_status VARCHAR(255) not null,
114 enrollment_id BIGINT not null unique,
115 foreign key (enrollment_id) references enrollment(id) on delete cascade
116);
117
118drop table if exists review;
119
120create table review (
121 id BIGSERIAL primary key,
122 rating INT not null,
123 comment VARCHAR(255),
124 review_date DATE default CURRENT_DATE not null,
125 enrollment_id BIGINT not null unique,
126 foreign key (enrollment_id) references enrollment(id) on delete cascade
127);
128
129drop table if exists course_translate;
130
131create table course_translate (
132 id BIGSERIAL primary key,
133 language VARCHAR(255) not null,
134 title_short VARCHAR(255) not null,
135 title VARCHAR(255) not null,
136 description_short VARCHAR(255) not null,
137 description VARCHAR(255) not null,
138 description_long VARCHAR(255) not null,
139 course_id BIGINT not null,
140 foreign key (course_id) references course(id) on
141delete
142 cascade
143);
144
145drop table if exists course_translate_what_will_be_learned;
146
147create table course_translate_what_will_be_learned (
148 course_translate_id BIGINT not null,
149 what_will_be_learned TEXT not null,
150 primary key (course_translate_id,
151what_will_be_learned),
152 foreign key (course_translate_id) references course_translate(id) on
153delete
154 cascade
155);
156
157drop table if exists course_content;
158
159create table course_content (
160 id BIGSERIAL primary key,
161 position INT not null,
162 course_version_id BIGINT not null,
163 foreign key (course_version_id) references course_version(id) on
164delete
165 cascade
166);
167
168drop table if exists course_content_translate;
169
170create table course_content_translate (
171 id BIGSERIAL primary key,
172 title VARCHAR(255) not null,
173 language VARCHAR(255) not null,
174 course_content_id BIGINT not null,
175 foreign key (course_content_id) references course_content(id) on
176delete
177 cascade
178);
179
180drop table if exists course_lecture;
181
182create table course_lecture (
183 id BIGSERIAL primary key,
184 duration_minutes INT not null,
185 position INT not null,
186 content_type VARCHAR(255) not null,
187 course_content_id BIGINT not null,
188 foreign key (course_content_id) references course_content(id) on
189delete
190 cascade
191);
192
193drop table if exists course_lecture_translate;
194
195create table course_lecture_translate (
196 id BIGSERIAL primary key,
197 title VARCHAR(255) not null,
198 language VARCHAR(255) not null,
199 content_file_name TEXT,
200 description TEXT not null,
201 content_text TEXT,
202 course_lecture_id BIGINT not null,
203 foreign key (course_lecture_id) references course_lecture(id) on
204delete
205 cascade
206);
207
208drop table if exists user_course_progress;
209
210create table user_course_progress (
211 id BIGSERIAL primary key,
212 completed BOOLEAN,
213 completed_at TIMESTAMP,
214 enrollment_id BIGINT not null,
215 course_lecture_id BIGINT not null,
216 foreign key (enrollment_id) references enrollment(id) on
217delete
218 cascade,
219 foreign key (course_lecture_id) references course_lecture(id) on
220 delete
221 cascade
222);
223
224drop table if exists verification_token;
225
226create table verification_token (
227 uuid BIGSERIAL primary key,
228 created_at TIMESTAMP default CURRENT_TIMESTAMP,
229 expired_at TIMESTAMP,
230 user_id BIGINT not null,
231 foreign key (user_id) references _user(id) on
232delete
233 cascade
234);
235
236drop table if exists tag;
237
238create table tag (
239 id BIGSERIAL primary key,
240 type VARCHAR(255) not null
241);
242
243drop table if exists tag_translate;
244
245create table tag_translate (
246 id BIGSERIAL primary key,
247 language VARCHAR(255) not null,
248 value VARCHAR(255) not null,
249 tag_id BIGINT not null,
250 foreign key (tag_id) references tag(id) on
251delete
252 cascade
253);
254
255drop table if exists user_tag;
256
257create table user_tag (
258 tag_id BIGINT not null,
259 user_id BIGINT not null,
260 primary key (tag_id,
261user_id),
262 foreign key (tag_id) references tag(id) on
263delete
264 cascade,
265 foreign key (user_id) references _user(id) on
266 delete
267 cascade
268);
269
270drop table if exists course_tag;
271
272create table course_tag (
273 tag_id BIGINT not null,
274 course_id BIGINT not null,
275 primary key (tag_id,
276course_id),
277 foreign key (tag_id) references tag(id) on
278delete
279 cascade,
280 foreign key (course_id) references course(id) on
281 delete
282 cascade
283);