diff --git a/server/db/schema/articles.sql b/server/db/schema/articles.sql new file mode 100644 index 0000000..1d0965a --- /dev/null +++ b/server/db/schema/articles.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS articles ( + id INTEGER PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ), + s3_url VARCHAR(256) NOT NULL, + description TEXT NOT NULL, + media_url VARCHAR(256) NOT NULL +); diff --git a/server/db/schema/class_enrollments.sql b/server/db/schema/class_enrollments.sql new file mode 100644 index 0000000..d451eee --- /dev/null +++ b/server/db/schema/class_enrollments.sql @@ -0,0 +1,19 @@ +CREATE TABLE IF NOT EXISTS class_enrollments ( + id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ), + student_id INTEGER NOT NULL, + class_id INTEGER NOT NULL, + attendance DATE NOT NULL, + + CONSTRAINT Pk_class_enrollments + PRIMARY KEY(student_id, class_id, id), + + CONSTRAINT fk_student + FOREIGN KEY(student_id) + REFERENCES student(id) + ON DELETE CASCADE, + + CONSTRAINT fk_class + FOREIGN KEY(class_id) + REFERENCES classes(id) + ON DELETE CASCADE +) diff --git a/server/db/schema/class_videos.sql b/server/db/schema/class_videos.sql new file mode 100644 index 0000000..5b52a33 --- /dev/null +++ b/server/db/schema/class_videos.sql @@ -0,0 +1,11 @@ +DROP TABLE IF EXISTS class_videos CASCADE; + +CREATE TABLE class_videos ( + id INTEGER PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ), + title VARCHAR(256) NOT NULL, + s3_url VARCHAR(256) NOT NULL, + description TEXT NOT NULL, + media_url TEXT NOT NULL, + class_id INTEGER NOT NULL, + FOREIGN KEY (class_id) REFERENCES classes(id) ON DELETE CASCADE +); diff --git a/server/db/schema/classes.sql b/server/db/schema/classes.sql new file mode 100644 index 0000000..f84fa2f --- /dev/null +++ b/server/db/schema/classes.sql @@ -0,0 +1,14 @@ +CREATE TYPE LEVEL AS ENUM ("beginner", "intermediate", "advanced") + +CREATE TABLE IF NOT EXISTS public.classes +( + id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ), + title VARCHAR(256) NOT NULL, + description TEXT, + location VARCHAR(256) NOT NULL, + capacity INT NOT NULL, + level LEVEL NOT NULL, + costume TEXT NOT NULL, + CONSTRAINT class_pkey PRIMARY KEY (id), +) + diff --git a/server/db/schema/classes_taught.sql b/server/db/schema/classes_taught.sql new file mode 100644 index 0000000..daa13a1 --- /dev/null +++ b/server/db/schema/classes_taught.sql @@ -0,0 +1,17 @@ +CREATE TABLE IF NOT EXISTS classes_taught ( + class_id INTEGER NOT NULL, + teacher_id INTEGER NOT NULL, + + CONSTRAINT Pk_classes_taught + PRIMARY KEY(class_id, teacher_id), + + CONSTRAINT fk_class + FOREIGN KEY(class_id) + REFERENCES classes(id) + ON DELETE CASCADE, + + CONSTRAINT fk_teacher + FOREIGN KEY(teacher_id) + REFERENCES teacher(id) + ON DELETE CASCADE +) \ No newline at end of file diff --git a/server/db/schema/event_enrollments.sql b/server/db/schema/event_enrollments.sql new file mode 100644 index 0000000..589d9a6 --- /dev/null +++ b/server/db/schema/event_enrollments.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS event_enrollments ( + id INTEGER PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),, + student_id INTEGER NOT NULL, + event_id INTEGER NOT NULL, + attendance BOOLEAN NOT NULL, + FOREIGN KEY (student_id) REFERENCES students (id) ON DELETE CASCADE, + FOREIGN KEY (event_id) REFERENCES events (id) ON DELETE CASCADE +); diff --git a/server/db/schema/events.sql b/server/db/schema/events.sql new file mode 100644 index 0000000..e1ccabe --- /dev/null +++ b/server/db/schema/events.sql @@ -0,0 +1,19 @@ +DROP TABLE IF EXISTS Events; +DROP TYPE IF EXISTS LEVEL; + +CREATE TYPE LEVEL AS ENUM ('beginner', 'intermediate', 'advanced'); + +CREATE TABLE Events ( + id SERIAL PRIMARY KEY, + location VARCHAR(256) NOT NULL, + title VARCHAR(256) NOT NULL, + description TEXT, + level LEVEL NOT NULL, + date DATE NOT NULL, + start_time TIME NOT NULL, + end_time TIME NOT NULL, + call_time TIME NOT NULL, + class_id INTEGER NOT NULL, + costume TEXT NOT NULL, + FOREIGN KEY (class_id) REFERENCES Classes(id) ON DELETE CASCADE +); \ No newline at end of file diff --git a/server/db/schema/sample.sql b/server/db/schema/sample.sql deleted file mode 100644 index 42b76b3..0000000 --- a/server/db/schema/sample.sql +++ /dev/null @@ -1,9 +0,0 @@ --- TODO: delete sample file - -DROP TABLE IF EXISTS sample CASCADE; - -CREATE TABLE sample ( - id SERIAL PRIMARY KEY, - content VARCHAR(256) NOT NULL -); - diff --git a/server/db/schema/scheduled_classes.sql b/server/db/schema/scheduled_classes.sql new file mode 100644 index 0000000..b3d61f4 --- /dev/null +++ b/server/db/schema/scheduled_classes.sql @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS scheduled_classes CASCADE; + +CREATE TABLE scheduled_classes ( + class_id INTEGER NOT NULL, + date DATE NOT NULL, + start_time TIME NOT NULL, + end_time TIME NOT NULL, + PRIMARY KEY (class_id, date), + FOREIGN KEY (class_id) REFERENCES classes(id) ON DELETE CASCADE +); diff --git a/server/db/schema/students.sql b/server/db/schema/students.sql new file mode 100644 index 0000000..a6bb671 --- /dev/null +++ b/server/db/schema/students.sql @@ -0,0 +1,8 @@ +CREATE TYPE LEVEL AS ENUM('beginner','intermediate','advanced'); + + +CREATE TABLE Student ( + id INTEGER NOT NULL PRIMARY KEY, + level LEVEL NOT NULL, + CONSTRAINT fk_user_student FOREIGN KEY (id) REFERENCES User (id) ON DELETE CASCADE +); \ No newline at end of file diff --git a/server/db/schema/teachers.sql b/server/db/schema/teachers.sql new file mode 100644 index 0000000..998b373 --- /dev/null +++ b/server/db/schema/teachers.sql @@ -0,0 +1,6 @@ +CREATE TABLE Teachers ( + id INTEGER NOT NULL PRIMARY KEY, + experience TEXT, + is_activated BOOL NOT NULL, + CONSTRAINT fk_user_teacher FOREIGN KEY (id) REFERENCES User (id) ON DELETE CASCADE + ); \ No newline at end of file diff --git a/server/db/schema/users.sql b/server/db/schema/users.sql index 81c31b7..e145232 100644 --- a/server/db/schema/users.sql +++ b/server/db/schema/users.sql @@ -2,12 +2,17 @@ -- DROP TABLE IF EXISTS public.users; +CREATE TYPE USER_ROLE AS ENUM('student', 'teacher', 'admin'); + CREATE TABLE IF NOT EXISTS public.users ( id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ), email character varying(256) COLLATE pg_catalog."default" NOT NULL, firebase_uid character varying(128) COLLATE pg_catalog."default" NOT NULL, role character varying(16) COLLATE pg_catalog."default" NOT NULL DEFAULT 'user'::character varying, + first_name character varying(128) NOT NULL, + last_name character varying(128) NOT NULL, + user_role USER_ROLE NOT NULL, CONSTRAINT user_pkey PRIMARY KEY (id), CONSTRAINT email UNIQUE (email), CONSTRAINT firebase_uid UNIQUE (firebase_uid), @@ -16,5 +21,5 @@ CREATE TABLE IF NOT EXISTS public.users TABLESPACE pg_default; -ALTER TABLE IF EXISTS public.users - OWNER to postgres; +-- ALTER TABLE IF EXISTS public.users +-- OWNER to postgres;