add coursework

This commit is contained in:
EgorGud
2026-11-27 22:21:54 +03:00
parent f50295872d
commit b3dc139855
3 changed files with 68 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
CREATE TABLE agents (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
full_name TEXT NOT NULL,
phone TEXT NOT NULL
);
CREATE TABLE clients (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
full_name TEXT NOT NULL,
phone TEXT NOT NULL,
passport TEXT NOT NULL
);
CREATE TABLE properties (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
address TEXT NOT NULL,
rooms INTEGER NOT NULL CHECK (rooms > 0),
area NUMERIC(8, 2) CHECK (area > 0),
price_per_month NUMERIC(10, 2) NOT NULL,
agent_id INTEGER REFERENCES agents(id)
);
CREATE TABLE leases (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
property_id INTEGER NOT NULL REFERENCES properties(id),
client_id INTEGER NOT NULL REFERENCES clients(id),
start_date DATE NOT NULL,
end_date DATE NOT NULL,
monthly_payment NUMERIC(10, 2) NOT NULL,
CHECK (end_date > start_date)
);
INSERT INTO agents (full_name, phone)
VALUES ('Иванова И. И.', '+7 999 123-45-67');
INSERT INTO clients (full_name, phone, passport)
VALUES ('Петров П. П.', '+7 999 765-43-21', '4512 635478');
INSERT INTO properties (address, rooms, area, price_per_month, agent_id)
VALUES ('ул. Ленина, 10, кв. 25', 2, 54.5, 45000, 1);
INSERT INTO leases (property_id, client_id, start_date, end_date, monthly_payment)
VALUES (1, 1, '2026-01-01', '2026-12-31', 45000);
@@ -0,0 +1,24 @@
name: kursach
services:
db:
image: postgres:16-alpine
container_name: kursach_postgres
restart: unless-stopped
environment:
POSTGRES_DB: kursach
POSTGRES_USER: kursach
POSTGRES_PASSWORD: kursach
ports:
- "5433:5432"
volumes:
- pgdata:/var/lib/postgresql/data
- ./sql:/docker-entrypoint-initdb.d:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U kursach -d kursach"]
interval: 5s
timeout: 3s
retries: 10
volumes:
pgdata:
Binary file not shown.