-
Notifications
You must be signed in to change notification settings - Fork 0
/
DbCourses.sql
77 lines (63 loc) · 2.24 KB
/
DbCourses.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
CREATE TABLE "users" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"nickname" varchar NOT NULL,
"first_name" varchar NOT NULL,
"last_name" varchar NOT NULL,
"birthday" date NOT NULL DEFAULT '2000/01/01',
"age" varchar NOT NULL DEFAULT 18,
"email" varchar UNIQUE NOT NULL,
"password" varchar NOT NULL,
"phone" varchar
);
CREATE TABLE "courses" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"title" varchar NOT NULL,
"summary" varchar NOT NULL,
"description" text NOT NULL,
"level_id" int NOT NULL,
"teacher_id" int NOT NULL
);
CREATE TABLE "course_videos" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"title" varchar NOT NULL,
"summary" varchar NOT NULL,
"description" text NOT NULL,
"url" varchar NOT NULL,
"id_course" int NOT NULL
);
CREATE TABLE "categories" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"title" varchar NOT NULL,
"description" text NOT NULL
);
CREATE TABLE "teachers" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"first_name" varchar NOT NULL,
"last_name" varchar NOT NULL,
"birthday" date NOT NULL DEFAULT '2000/01/01',
"age" varchar NOT NULL DEFAULT 18,
"email" varchar UNIQUE NOT NULL,
"phone" varchar
);
CREATE TABLE "user_courses" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"course_id" int NOT NULL,
"user_id" int NOT NULL
);
CREATE TABLE "course_category" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"course_id" int NOT NULL,
"category_id" int NOT NULL
);
CREATE TABLE "levels" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" varchar NOT NULL,
"description" varchar NOT NULL
);
ALTER TABLE "user_courses" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
ALTER TABLE "user_courses" ADD FOREIGN KEY ("course_id") REFERENCES "courses" ("id");
ALTER TABLE "course_videos" ADD FOREIGN KEY ("id_course") REFERENCES "courses" ("id");
ALTER TABLE "courses" ADD FOREIGN KEY ("level_id") REFERENCES "levels" ("id");
ALTER TABLE "courses" ADD FOREIGN KEY ("teacher_id") REFERENCES "teachers" ("id");
ALTER TABLE "course_category" ADD FOREIGN KEY ("category_id") REFERENCES "categories" ("id");
ALTER TABLE "course_category" ADD FOREIGN KEY ("course_id") REFERENCES "courses" ("id");