-- Create courses table
CREATE TABLE courses (
tenant_id UUID,
course_id UUID DEFAULT gen_random_uuid(),
course_name VARCHAR(100) NOT NULL,
course_description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
vector_embedding VECTOR(768), -- Adjust the dimensions as needed,
PRIMARY KEY (tenant_id, course_id),
FOREIGN KEY (tenant_id) REFERENCES tenants(id)
);
-- Create enrollments table
CREATE TABLE enrollments (
tenant_id UUID,
enrollment_id UUID DEFAULT gen_random_uuid(),
course_id UUID,
student_id UUID,
enrollment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (tenant_id, enrollment_id),
FOREIGN KEY (tenant_id, course_id) REFERENCES courses(tenant_id, course_id),
FOREIGN KEY (tenant_id, student_id) REFERENCES tenant_users(tenant_id, user_id)
);
-- Create grades table
CREATE TABLE grades (
tenant_id UUID,
grade_id UUID DEFAULT gen_random_uuid(),
course_id UUID,
student_id UUID,
grade DECIMAL(5, 2),
grade_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (tenant_id, grade_id),
FOREIGN KEY (tenant_id, course_id) REFERENCES courses(tenant_id, course_id),
FOREIGN KEY (tenant_id, student_id) REFERENCES tenant_users(tenant_id, user_id)
);
-- Create feedback table
CREATE TABLE feedback (
tenant_id UUID,
feedback_id UUID DEFAULT gen_random_uuid(),
course_id UUID,
student_id UUID,
teacher_id UUID,
feedback_text TEXT,
feedback_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
vector_embedding VECTOR(768), -- Adjust the dimensions as needed
PRIMARY KEY (tenant_id, feedback_id),
FOREIGN KEY (tenant_id, course_id) REFERENCES courses(tenant_id, course_id),
FOREIGN KEY (tenant_id, student_id) REFERENCES tenant_users(tenant_id, user_id),
FOREIGN KEY (tenant_id, teacher_id) REFERENCES tenant_users(tenant_id, user_id)
);
-- Create homework table
CREATE TABLE homework (
tenant_id UUID,
homework_id UUID DEFAULT gen_random_uuid(),
course_id UUID,
teacher_id UUID,
homework_description TEXT,
due_date DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
vector_embedding VECTOR(768), -- Adjust the dimensions as needed
PRIMARY KEY (tenant_id, homework_id),
FOREIGN KEY (tenant_id, course_id) REFERENCES courses(tenant_id, course_id),
FOREIGN KEY (tenant_id, teacher_id) REFERENCES tenant_users(tenant_id, user_id)
);
-- Create homework_submissions table
CREATE TABLE homework_submissions (
tenant_id UUID,
submission_id UUID DEFAULT gen_random_uuid(),
homework_id UUID,
student_id UUID,
submission_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
submission_file BYTEA,
grade DECIMAL(5, 2),
feedback TEXT,
vector_embedding VECTOR(768), -- Adjust the dimensions as needed
PRIMARY KEY (tenant_id, submission_id),
FOREIGN KEY (tenant_id, homework_id) REFERENCES homework(tenant_id, homework_id),
FOREIGN KEY (tenant_id, student_id) REFERENCES tenant_users(tenant_id, user_id)
);