main
Dmitry 9 months ago
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,38 @@
-- Товары
CREATE TABLE products (
product_id INT PRIMARY KEY AUTO_INCREMENT,
product_name VARCHAR(255) NOT NULL,
description TEXT,
price DECIMAL(10, 2) NOT NULL,
stock_quantity INT NOT NULL
);
-- Клиенты
CREATE TABLE customers (
customer_id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL
);
-- Заказы
CREATE TABLE orders (
order_id INT PRIMARY KEY AUTO_INCREMENT,
customer_id INT,
order_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
total_amount DECIMAL(10, 2) NOT NULL,
status VARCHAR(50) DEFAULT 'В обработке',
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
-- Товары в заказах
CREATE TABLE order_items (
order_item_id INT PRIMARY KEY AUTO_INCREMENT,
order_id INT,
product_id INT,
quantity INT NOT NULL,
subtotal DECIMAL(10, 2) NOT NULL,
FOREIGN KEY (order_id) REFERENCES orders(order_id),
FOREIGN KEY (product_id) REFERENCES products(product_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…
Cancel
Save

Powered by TurnKey Linux.