parent
6bb949ec18
commit
6185afb14b
@ -0,0 +1,34 @@
|
|||||||
|
-- Курсы
|
||||||
|
CREATE TABLE courses (
|
||||||
|
course_id SERIAL PRIMARY KEY,
|
||||||
|
course_name VARCHAR(255) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
start_date DATE,
|
||||||
|
end_date DATE
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Студенты
|
||||||
|
CREATE TABLE students (
|
||||||
|
student_id SERIAL PRIMARY KEY,
|
||||||
|
first_name VARCHAR(255) NOT NULL,
|
||||||
|
last_name VARCHAR(255) NOT NULL,
|
||||||
|
email VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
date_of_birth DATE
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Уроки
|
||||||
|
CREATE TABLE lessons (
|
||||||
|
lesson_id SERIAL PRIMARY KEY,
|
||||||
|
lesson_name VARCHAR(255) NOT NULL,
|
||||||
|
content TEXT,
|
||||||
|
video_url VARCHAR(255),
|
||||||
|
lesson_order INT
|
||||||
|
);
|
||||||
|
|
||||||
|
-- m2m students to courses
|
||||||
|
CREATE TABLE student_courses (
|
||||||
|
student_id INT REFERENCES students(student_id),
|
||||||
|
course_id INT REFERENCES courses(course_id),
|
||||||
|
enrollment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (student_id, course_id)
|
||||||
|
);
|
@ -0,0 +1,43 @@
|
|||||||
|
-- Пользователи
|
||||||
|
CREATE TABLE users (
|
||||||
|
user_id SERIAL PRIMARY KEY,
|
||||||
|
username VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
email VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
password VARCHAR(255) NOT NULL,
|
||||||
|
full_name VARCHAR(255),
|
||||||
|
date_joined TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Посты
|
||||||
|
CREATE TABLE posts (
|
||||||
|
post_id SERIAL PRIMARY KEY,
|
||||||
|
user_id INT REFERENCES users(user_id),
|
||||||
|
content TEXT NOT NULL,
|
||||||
|
post_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Комментарии
|
||||||
|
CREATE TABLE comments (
|
||||||
|
comment_id SERIAL PRIMARY KEY,
|
||||||
|
user_id INT REFERENCES users(user_id),
|
||||||
|
post_id INT REFERENCES posts(post_id),
|
||||||
|
content TEXT NOT NULL,
|
||||||
|
comment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Лайки
|
||||||
|
CREATE TABLE likes (
|
||||||
|
like_id SERIAL PRIMARY KEY,
|
||||||
|
user_id INT REFERENCES users(user_id),
|
||||||
|
post_id INT REFERENCES posts(post_id),
|
||||||
|
comment_id INT REFERENCES comments(comment_id),
|
||||||
|
like_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Друзья
|
||||||
|
CREATE TABLE friends (
|
||||||
|
friendship_id SERIAL PRIMARY KEY,
|
||||||
|
user1_id INT REFERENCES users(user_id),
|
||||||
|
user2_id INT REFERENCES users(user_id),
|
||||||
|
friendship_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
@ -0,0 +1,16 @@
|
|||||||
|
CREATE TABLE categories (
|
||||||
|
category_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
category_name VARCHAR(255) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE tasks (
|
||||||
|
task_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
task_name VARCHAR(255) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
due_date DATE,
|
||||||
|
category_id INT,
|
||||||
|
completed BOOLEAN DEFAULT FALSE,
|
||||||
|
FOREIGN KEY (category_id) REFERENCES categories(category_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO categories (category_name) VALUES ('Работа'), ('Дом'), ('Личное');
|
Loading…
Reference in new issue