generated from csfilipinyi/cyf-final-project-pgsql-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSlackerHackers_postgres_create.sql
83 lines (59 loc) · 1.92 KB
/
SlackerHackers_postgres_create.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
CREATE TABLE "mentors" (
"id" serial NOT NULL,
"slackUserId" character varying(20) NOT NULL UNIQUE,
"defaultLocationId" bigint NOT NULL,
CONSTRAINT "mentors_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
CREATE TABLE "trainees" (
"id" serial NOT NULL,
"slackUserId" character varying(20) NOT NULL UNIQUE,
"classId" bigint NOT NULL,
CONSTRAINT "trainees_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
CREATE TABLE "locations" (
"id" serial NOT NULL,
"name" character varying(40) NOT NULL UNIQUE,
CONSTRAINT "locations_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
CREATE TABLE "classes" (
"id" serial NOT NULL,
"locationId" bigint NOT NULL,
"name" character varying(40) NOT NULL,
"startDate" DATE NOT NULL,
CONSTRAINT "classes_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
CREATE TABLE "thresholds" (
"id" serial NOT NULL,
"mentorId" bigint NOT NULL,
"classId" bigint NOT NULL,
"postsWeight" integer NOT NULL,
"callsCountWeight" integer NOT NULL,
"callsTimeWeight" integer NOT NULL,
"threshold" integer NOT NULL,
CONSTRAINT "thresholds_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
CREATE TABLE "posts" (
"id" serial NOT NULL,
"slackUserId" character varying(20) NOT NULL,
"slackChannelId" character varying(20) NOT NULL,
"timestamp" DATE NOT NULL,
"isReply" BOOLEAN NOT NULL DEFAULT 'false',
CONSTRAINT "posts_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
ALTER TABLE "mentors" ADD CONSTRAINT "mentors_fk0" FOREIGN KEY ("defaultLocationId") REFERENCES "locations"("id");
ALTER TABLE "trainees" ADD CONSTRAINT "trainees_fk0" FOREIGN KEY ("classId") REFERENCES "classes"("id");
ALTER TABLE "classes" ADD CONSTRAINT "classes_fk0" FOREIGN KEY ("locationId") REFERENCES "locations"("id");
ALTER TABLE "thresholds" ADD CONSTRAINT "thresholds_fk0" FOREIGN KEY ("mentorId") REFERENCES "mentors"("id");
ALTER TABLE "thresholds" ADD CONSTRAINT "thresholds_fk1" FOREIGN KEY ("classId") REFERENCES "classes"("id");