Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/ctc-uci/cse into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
stevem-zhou committed Dec 7, 2024
2 parents a12fb49 + 5906f23 commit 24f7239
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 11 deletions.
6 changes: 6 additions & 0 deletions server/db/schema/articles.sql
Original file line number Diff line number Diff line change
@@ -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
);
19 changes: 19 additions & 0 deletions server/db/schema/class_enrollments.sql
Original file line number Diff line number Diff line change
@@ -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
)
11 changes: 11 additions & 0 deletions server/db/schema/class_videos.sql
Original file line number Diff line number Diff line change
@@ -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
);
14 changes: 14 additions & 0 deletions server/db/schema/classes.sql
Original file line number Diff line number Diff line change
@@ -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),
)

17 changes: 17 additions & 0 deletions server/db/schema/classes_taught.sql
Original file line number Diff line number Diff line change
@@ -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
)
8 changes: 8 additions & 0 deletions server/db/schema/event_enrollments.sql
Original file line number Diff line number Diff line change
@@ -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
);
19 changes: 19 additions & 0 deletions server/db/schema/events.sql
Original file line number Diff line number Diff line change
@@ -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
);
9 changes: 0 additions & 9 deletions server/db/schema/sample.sql

This file was deleted.

10 changes: 10 additions & 0 deletions server/db/schema/scheduled_classes.sql
Original file line number Diff line number Diff line change
@@ -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
);
8 changes: 8 additions & 0 deletions server/db/schema/students.sql
Original file line number Diff line number Diff line change
@@ -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
);
6 changes: 6 additions & 0 deletions server/db/schema/teachers.sql
Original file line number Diff line number Diff line change
@@ -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
);
9 changes: 7 additions & 2 deletions server/db/schema/users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;

0 comments on commit 24f7239

Please sign in to comment.