| 1 | drop table if exists _user;
|
|---|
| 2 |
|
|---|
| 3 | create 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 |
|
|---|
| 17 | drop table if exists meeting_email_reminder;
|
|---|
| 18 |
|
|---|
| 19 | create 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
|
|---|
| 27 | delete
|
|---|
| 28 | cascade
|
|---|
| 29 | );
|
|---|
| 30 |
|
|---|
| 31 | drop table if exists user_favorite_course_ids;
|
|---|
| 32 |
|
|---|
| 33 | create table user_favorite_course_ids (
|
|---|
| 34 | user_id BIGINT not null,
|
|---|
| 35 | favorite_course_ids BIGINT not null,
|
|---|
| 36 | primary key (user_id,
|
|---|
| 37 | favorite_course_ids),
|
|---|
| 38 | foreign key (user_id) references _user(id) on
|
|---|
| 39 | delete
|
|---|
| 40 | cascade
|
|---|
| 41 | );
|
|---|
| 42 |
|
|---|
| 43 | drop table if exists expert;
|
|---|
| 44 |
|
|---|
| 45 | create 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 |
|
|---|
| 53 | drop table if exists course;
|
|---|
| 54 |
|
|---|
| 55 | create 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 |
|
|---|
| 64 | drop table if exists expert_course;
|
|---|
| 65 |
|
|---|
| 66 | create table expert_course (
|
|---|
| 67 | course_id BIGINT not null,
|
|---|
| 68 | expert_id BIGINT not null,
|
|---|
| 69 | primary key (expert_id,
|
|---|
| 70 | course_id),
|
|---|
| 71 | foreign key (expert_id) references expert(id) on
|
|---|
| 72 | delete
|
|---|
| 73 | cascade,
|
|---|
| 74 | foreign key (course_id) references course(id) on
|
|---|
| 75 | delete
|
|---|
| 76 | cascade
|
|---|
| 77 | );
|
|---|
| 78 |
|
|---|
| 79 | drop table if exists course_version;
|
|---|
| 80 |
|
|---|
| 81 | create 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
|
|---|
| 88 | delete
|
|---|
| 89 | cascade
|
|---|
| 90 | );
|
|---|
| 91 |
|
|---|
| 92 | drop table if exists enrollment;
|
|---|
| 93 |
|
|---|
| 94 | create 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 |
|
|---|
| 106 | drop table if exists payment;
|
|---|
| 107 |
|
|---|
| 108 | create 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 |
|
|---|
| 118 | drop table if exists review;
|
|---|
| 119 |
|
|---|
| 120 | create 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 |
|
|---|
| 129 | drop table if exists course_translate;
|
|---|
| 130 |
|
|---|
| 131 | create 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
|
|---|
| 141 | delete
|
|---|
| 142 | cascade
|
|---|
| 143 | );
|
|---|
| 144 |
|
|---|
| 145 | drop table if exists course_translate_what_will_be_learned;
|
|---|
| 146 |
|
|---|
| 147 | create 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,
|
|---|
| 151 | what_will_be_learned),
|
|---|
| 152 | foreign key (course_translate_id) references course_translate(id) on
|
|---|
| 153 | delete
|
|---|
| 154 | cascade
|
|---|
| 155 | );
|
|---|
| 156 |
|
|---|
| 157 | drop table if exists course_content;
|
|---|
| 158 |
|
|---|
| 159 | create 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
|
|---|
| 164 | delete
|
|---|
| 165 | cascade
|
|---|
| 166 | );
|
|---|
| 167 |
|
|---|
| 168 | drop table if exists course_content_translate;
|
|---|
| 169 |
|
|---|
| 170 | create 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
|
|---|
| 176 | delete
|
|---|
| 177 | cascade
|
|---|
| 178 | );
|
|---|
| 179 |
|
|---|
| 180 | drop table if exists course_lecture;
|
|---|
| 181 |
|
|---|
| 182 | create 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
|
|---|
| 189 | delete
|
|---|
| 190 | cascade
|
|---|
| 191 | );
|
|---|
| 192 |
|
|---|
| 193 | drop table if exists course_lecture_translate;
|
|---|
| 194 |
|
|---|
| 195 | create 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
|
|---|
| 204 | delete
|
|---|
| 205 | cascade
|
|---|
| 206 | );
|
|---|
| 207 |
|
|---|
| 208 | drop table if exists user_course_progress;
|
|---|
| 209 |
|
|---|
| 210 | create 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
|
|---|
| 217 | delete
|
|---|
| 218 | cascade,
|
|---|
| 219 | foreign key (course_lecture_id) references course_lecture(id) on
|
|---|
| 220 | delete
|
|---|
| 221 | cascade
|
|---|
| 222 | );
|
|---|
| 223 |
|
|---|
| 224 | drop table if exists verification_token;
|
|---|
| 225 |
|
|---|
| 226 | create 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
|
|---|
| 232 | delete
|
|---|
| 233 | cascade
|
|---|
| 234 | );
|
|---|
| 235 |
|
|---|
| 236 | drop table if exists tag;
|
|---|
| 237 |
|
|---|
| 238 | create table tag (
|
|---|
| 239 | id BIGSERIAL primary key,
|
|---|
| 240 | type VARCHAR(255) not null
|
|---|
| 241 | );
|
|---|
| 242 |
|
|---|
| 243 | drop table if exists tag_translate;
|
|---|
| 244 |
|
|---|
| 245 | create 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
|
|---|
| 251 | delete
|
|---|
| 252 | cascade
|
|---|
| 253 | );
|
|---|
| 254 |
|
|---|
| 255 | drop table if exists user_tag;
|
|---|
| 256 |
|
|---|
| 257 | create table user_tag (
|
|---|
| 258 | tag_id BIGINT not null,
|
|---|
| 259 | user_id BIGINT not null,
|
|---|
| 260 | primary key (tag_id,
|
|---|
| 261 | user_id),
|
|---|
| 262 | foreign key (tag_id) references tag(id) on
|
|---|
| 263 | delete
|
|---|
| 264 | cascade,
|
|---|
| 265 | foreign key (user_id) references _user(id) on
|
|---|
| 266 | delete
|
|---|
| 267 | cascade
|
|---|
| 268 | );
|
|---|
| 269 |
|
|---|
| 270 | drop table if exists course_tag;
|
|---|
| 271 |
|
|---|
| 272 | create table course_tag (
|
|---|
| 273 | tag_id BIGINT not null,
|
|---|
| 274 | course_id BIGINT not null,
|
|---|
| 275 | primary key (tag_id,
|
|---|
| 276 | course_id),
|
|---|
| 277 | foreign key (tag_id) references tag(id) on
|
|---|
| 278 | delete
|
|---|
| 279 | cascade,
|
|---|
| 280 | foreign key (course_id) references course(id) on
|
|---|
| 281 | delete
|
|---|
| 282 | cascade
|
|---|
| 283 | );
|
|---|