курсач

This commit is contained in:
kosios.obsi
2026-11-27 13:34:24 +03:00
parent 8711598b84
commit 8d8104dccb
3 changed files with 81 additions and 0 deletions
@@ -0,0 +1,17 @@
services:
db:
image: postgres:16-alpine
container_name: clinic_postgres
restart: unless-stopped
environment:
POSTGRES_DB: clinic_db
POSTGRES_USER: clinic_user
POSTGRES_PASSWORD: clinic_password
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
volumes:
pgdata:
+64
View File
@@ -0,0 +1,64 @@
CREATE TABLE specialties (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL UNIQUE
);
CREATE TABLE doctors (
id SERIAL PRIMARY KEY,
full_name VARCHAR(150) NOT NULL,
specialty_id INT NOT NULL REFERENCES specialties(id) ON DELETE RESTRICT,
cabinet VARCHAR(20) NOT NULL
);
CREATE TABLE patients (
id SERIAL PRIMARY KEY,
full_name VARCHAR(150) NOT NULL,
phone VARCHAR(20) NOT NULL UNIQUE,
birth_date DATE NOT NULL
);
CREATE TABLE schedule_slots (
id SERIAL PRIMARY KEY,
doctor_id INT NOT NULL REFERENCES doctors(id) ON DELETE CASCADE,
slot_start TIMESTAMP NOT NULL,
slot_end TIMESTAMP NOT NULL,
CONSTRAINT chk_slot_time CHECK (slot_end > slot_start),
CONSTRAINT uq_doctor_slot_start UNIQUE (doctor_id, slot_start)
);
CREATE TABLE appointments (
id SERIAL PRIMARY KEY,
slot_id INT NOT NULL UNIQUE REFERENCES schedule_slots(id) ON DELETE CASCADE,
patient_id INT NOT NULL REFERENCES patients(id) ON DELETE CASCADE,
status VARCHAR(20) NOT NULL DEFAULT 'booked'
CHECK (status IN ('booked', 'cancelled', 'completed')),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO specialties (name) VALUES
('Терапевт'),
('Кардиолог'),
('Офтальмолог');
INSERT INTO doctors (full_name, specialty_id, cabinet) VALUES
('Казаков Егор Михалович', 1, '101'),
('Раджабов Амирхан Исламович', 2, '204'),
('Беляев Антон Сергеевич', 3, '305');
INSERT INTO patients (full_name, phone, birth_date) VALUES
('Иванов Иван Иванович', '+79001112233', '1995-04-12'),
('Смирнов Дмитрий Олегович', '+79004445566', '1988-11-03'),
('Волкова Мария Андреевна', '+79007778899', '2001-07-25');
INSERT INTO schedule_slots (doctor_id, slot_start, slot_end) VALUES
(1, '2026-12-01 09:00:00', '2026-12-01 09:30:00'),
(1, '2026-12-01 09:30:00', '2026-12-01 10:00:00'),
(1, '2026-12-01 10:00:00', '2026-12-01 10:30:00'),
(2, '2026-12-01 11:00:00', '2026-12-01 11:30:00'),
(2, '2026-12-01 11:30:00', '2026-12-01 12:00:00'),
(3, '2026-12-01 14:00:00', '2026-12-01 14:30:00');
INSERT INTO appointments (slot_id, patient_id, status) VALUES
(1, 1, 'booked'),
(4, 2, 'booked');