51 lines
1.3 KiB
SQL
51 lines
1.3 KiB
SQL
DROP SCHEMA IF EXISTS edu_platform CASCADE;
|
|
CREATE SCHEMA edu_platform;
|
|
|
|
drop table if exists edu_platform.users;
|
|
CREATE TABLE edu_platform.users (
|
|
id SERIAL PRIMARY KEY,
|
|
name VARCHAR(100) NOT NULL,
|
|
age INT NOT NULL,
|
|
email VARCHAR(100) NOT NULL,
|
|
registration_date DATE NOT NULL
|
|
);
|
|
|
|
drop table if exists edu_platform.courses;
|
|
CREATE TABLE edu_platform.courses (
|
|
id SERIAL PRIMARY KEY,
|
|
title VARCHAR(100) NOT NULL,
|
|
category VARCHAR(100) NOT NULL,
|
|
created_at DATE not NULL
|
|
);
|
|
|
|
drop table if exists edu_platform.lessons;
|
|
create TABLE edu_platform.lessons (
|
|
id SERIAL PRIMARY KEY,
|
|
course_id INT NOT NULL,
|
|
title VARCHAR(100) NOT NULL,
|
|
duration_min INT NOT null,
|
|
FOREIGN KEY (course_id) REFERENCES edu_platform.courses(id)
|
|
);
|
|
|
|
drop table if exists edu_platform.enrollments;
|
|
create TABLE edu_platform.enrollments (
|
|
id SERIAL PRIMARY KEY,
|
|
user_id INT NOT NULL,
|
|
course_id INT NOT NULL,
|
|
enrolled_at DATE not null,
|
|
foreign key (user_id) references edu_platform.users(id),
|
|
foreign key (course_id) references edu_platform.courses(id)
|
|
);
|
|
|
|
drop table if exists edu_platform.lesson_views;
|
|
create table edu_platform.lesson_views (
|
|
id SERIAL PRIMARY KEY,
|
|
user_id INT NOT NULL,
|
|
lesson_id INT NOT NULL,
|
|
viewed_at TIMESTAMP not null,
|
|
foreign key (user_id) references edu_platform.users(id),
|
|
foreign key (lesson_id) references edu_platform.lessons(id)
|
|
);
|
|
|
|
|