4 fields snake case

This commit is contained in:
2026-04-05 15:41:06 +03:00
parent 11ba82ebf0
commit 35354b1cd5
2 changed files with 84 additions and 80 deletions

View File

@ -186,12 +186,12 @@ let script = 'INSERT INTO "Person" (full_name, passwd_hash) ' + Values(() => {
let person_id = 1 let person_id = 1
// Master // Master
script += 'INSERT INTO "Master" ("Person_id", passport, readme) ' + Values(() => { script += 'INSERT INTO "Master" (person_id, passport, readme) ' + Values(() => {
return `(${person_id++}, ${GenPassport()}, 'aboba')` return `(${person_id++}, ${GenPassport()}, 'aboba')`
}) })
// Client // Client
script += 'INSERT INTO "Client" ("Person_id", phone, email, billing_account) ' + Values(() => { script += 'INSERT INTO "Client" (person_id, phone, email, billing_account) ' + Values(() => {
return `(${person_id++}, ${GenPhone()}, ${GenEmail()}, ${GenBillingAccount()})` return `(${person_id++}, ${GenPhone()}, ${GenEmail()}, ${GenBillingAccount()})`
}) })
@ -201,22 +201,22 @@ script += 'INSERT INTO "Studio" (address, capacity, begin_date, duration, usage_
}) })
// Course // Course
script += 'INSERT INTO "Course" ("Master_id", name, price, deadline_date) ' + Values(() => { script += 'INSERT INTO "Course" (master_id, name, price, deadline_date) ' + Values(() => {
return `(${GenInt(1, COUNT + 1)}, 'курс ${GenMaxUInt(3)}', ${GenPrice()}, ${GenTimestamp()})` return `(${GenInt(1, COUNT + 1)}, 'курс ${GenMaxUInt(3)}', ${GenPrice()}, ${GenTimestamp()})`
}) })
// Class // Class
script += 'INSERT INTO "Class" (begin_date, "Course_id", "Studio_id", name, type, duration) ' + Values(() => { script += 'INSERT INTO "Class" (begin_date, course_id, studio_id, name, type, duration) ' + Values(() => {
return `(${GenTimestamp()}, ${GenInt(1, COUNT + 1)}, ${GenInt(1, COUNT + 1)}, 'занятие ${GenMaxUInt(100)}', '${ClassTypes[GenMaxUInt(ClassTypes.length)]}', ${GenIntervalHours()})` return `(${GenTimestamp()}, ${GenInt(1, COUNT + 1)}, ${GenInt(1, COUNT + 1)}, 'занятие ${GenMaxUInt(100)}', '${ClassTypes[GenMaxUInt(ClassTypes.length)]}', ${GenIntervalHours()})`
}) })
// Class_Master // Class_Master
script += Many(`INSERT INTO "Class_Master" ("Class_begin_date", "Class_Course_id", "Master_id")`, () => { script += Many(`INSERT INTO "Class_Master" (class_begin_date, class_course_id, master_id)`, () => {
return `SELECT begin_date, "Course_id", ${GenInt(1, COUNT + 1)} FROM "Class" LIMIT 1 OFFSET ${GenInt(0, COUNT)}` return `SELECT begin_date, course_id, ${GenInt(1, COUNT + 1)} FROM "Class" LIMIT 1 OFFSET ${GenInt(0, COUNT)}`
}) })
// Registration // Registration
script += 'INSERT INTO "Registration" ("Client_id", "Course_id", date, status) ' + Values(() => { script += 'INSERT INTO "Registration" (client_id, course_id, date, status) ' + Values(() => {
return `(${GenInt(COUNT + 1, COUNT * 2 + 1)}, ${GenInt(1, COUNT + 1)}, ${GenTimestamp()}, 'Paid')` return `(${GenInt(COUNT + 1, COUNT * 2 + 1)}, ${GenInt(1, COUNT + 1)}, ${GenTimestamp()}, 'Paid')`
}, 0.5) }, 0.5)
@ -226,18 +226,18 @@ script += 'INSERT INTO "FoodProductEnum" (name, avg_price) ' + Values(() => {
}) })
// FoodProduct // FoodProduct
script += Many(`INSERT INTO "FoodProduct" ("FoodProductEnum_id", "Class_begin_date", "Class_Course_id", buy_price, buy_date, delivery_price, delivery_date, expires_date)`, () => { script += Many(`INSERT INTO "FoodProduct" (food_product_enum_id, class_begin_date, class_course_id, buy_price, buy_date, delivery_price, delivery_date, expires_date)`, () => {
return `SELECT ${GenInt(1, COUNT + 1)}, begin_date, "Course_id", ${GenPrice()}, ${GenTimestamp()}, ${GenPrice()}, ${GenTimestamp()}, ${GenTimestamp()} FROM "Class" LIMIT 1 OFFSET ${GenInt(0, COUNT)}` return `SELECT ${GenInt(1, COUNT + 1)}, begin_date, course_id, ${GenPrice()}, ${GenTimestamp()}, ${GenPrice()}, ${GenTimestamp()}, ${GenTimestamp()} FROM "Class" LIMIT 1 OFFSET ${GenInt(0, COUNT)}`
}) })
// Equipment // Equipment
script += 'INSERT INTO "Equipment" ("Studio_id", name, usage_price, usage_type, delivery_price, delivery_date) ' + Values(() => { script += 'INSERT INTO "Equipment" (studio_id, name, usage_price, usage_type, delivery_price, delivery_date) ' + Values(() => {
return `(${GenInt(1, COUNT + 1)}, 'оборудование ${GenMaxUInt(100)}', ${GenPrice(300)}, '${UsageTypes[GenMaxUInt(UsageTypes.length)]}', ${GenPrice(200)}, ${GenTimestamp()})` return `(${GenInt(1, COUNT + 1)}, 'оборудование ${GenMaxUInt(100)}', ${GenPrice(300)}, '${UsageTypes[GenMaxUInt(UsageTypes.length)]}', ${GenPrice(200)}, ${GenTimestamp()})`
}) })
// Class_Equipment // Class_Equipment
script += Many(`INSERT INTO "Class_Equipment" ("Class_begin_date", "Class_Course_id", "Equipment_id")`, () => { script += Many(`INSERT INTO "Class_Equipment" (class_begin_date, class_course_id, equipment_id)`, () => {
return `SELECT begin_date, "Course_id", ${GenInt(1, COUNT + 1)} FROM "Class" LIMIT 1 OFFSET ${GenInt(0, COUNT)}` return `SELECT begin_date, course_id, ${GenInt(1, COUNT + 1)} FROM "Class" LIMIT 1 OFFSET ${GenInt(0, COUNT)}`
}) })
// DrugEnum // DrugEnum
@ -246,17 +246,17 @@ script += 'INSERT INTO "DrugEnum" (name, avg_price) ' + Values(() => {
}) })
// Drug // Drug
script += 'INSERT INTO "Drug" ("DrugEnum_id", "Course_id", buy_price, buy_date, delivery_price, delivery_date, expires_date) ' + Values(() => { script += 'INSERT INTO "Drug" (drug_enum_id, course_id, buy_price, buy_date, delivery_price, delivery_date, expires_date) ' + Values(() => {
return `(${GenInt(1, COUNT + 1)}, ${GenInt(1, COUNT + 1)}, ${GenPrice()}, ${GenTimestamp()}, ${GenPrice()}, ${GenTimestamp()}, ${GenTimestamp()})` return `(${GenInt(1, COUNT + 1)}, ${GenInt(1, COUNT + 1)}, ${GenPrice()}, ${GenTimestamp()}, ${GenPrice()}, ${GenTimestamp()}, ${GenTimestamp()})`
}) })
// DrugIntolerance // DrugIntolerance
script += 'INSERT INTO "DrugIntolerance" ("Person_id", "DrugEnum_id") ' + Values(() => { script += 'INSERT INTO "DrugIntolerance" (person_id, drug_enum_id) ' + Values(() => {
return `(${GenInt(1, COUNT * 2 + 1)}, ${GenInt(1, COUNT + 1)})` return `(${GenInt(1, COUNT * 2 + 1)}, ${GenInt(1, COUNT + 1)})`
}) })
// ActivityLog // ActivityLog
script += 'INSERT INTO "ActivityLog" ("Person_id", action) ' + Values(() => { script += 'INSERT INTO "ActivityLog" (person_id, action) ' + Values(() => {
return `(${GenInt(1, COUNT * 2 + 1)}, 'login')` return `(${GenInt(1, COUNT * 2 + 1)}, 'login')`
}) })

View File

@ -10,39 +10,41 @@ CREATE TYPE "UsageType" AS ENUM (
CREATE TABLE "Person" ( CREATE TABLE "Person" (
id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, person_id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
full_name text NOT NULL, full_name text NOT NULL,
passwd_hash bytea NOT NULL passwd_hash bytea NOT NULL
); );
CREATE TABLE "Client" ( CREATE TABLE "Client" (
"Person_id" int UNIQUE NOT NULL, person_id int PRIMARY KEY,
phone text NOT NULL, phone text NOT NULL,
email text NOT NULL, email text NOT NULL,
billing_account text NOT NULL, billing_account text NOT NULL,
FOREIGN KEY ("Person_id") REFERENCES "Person" (id) FOREIGN KEY (person_id) REFERENCES "Person" (person_id)
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE TABLE "Master" ( CREATE TABLE "Master" (
"Person_id" int UNIQUE NOT NULL, person_id int PRIMARY KEY,
passport text UNIQUE NOT NULL, passport text UNIQUE NOT NULL,
readme text NOT NULL, readme text NOT NULL,
FOREIGN KEY ("Person_id") REFERENCES "Person" (id) FOREIGN KEY (person_id) REFERENCES "Person" (person_id)
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE TABLE "Studio" ( CREATE TABLE "Studio" (
id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, studio_id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
address text UNIQUE NOT NULL, address text UNIQUE NOT NULL,
capacity int NOT NULL CHECK (capacity > 0), capacity int NOT NULL CHECK (capacity > 0),
begin_date timestamptz NOT NULL, begin_date timestamptz NOT NULL,
@ -53,13 +55,14 @@ CREATE TABLE "Studio" (
CREATE TABLE "Course" ( CREATE TABLE "Course" (
id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, course_id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
"Master_id" int,
master_id int,
name text NOT NULL, name text NOT NULL,
price real NOT NULL CHECK (price > 0), price real NOT NULL CHECK (price > 0),
deadline_date timestamptz NOT NULL, deadline_date timestamptz NOT NULL,
FOREIGN KEY ("Master_id") REFERENCES "Master" ("Person_id") FOREIGN KEY (master_id) REFERENCES "Master" (person_id)
ON DELETE SET NULL ON DELETE SET NULL
ON UPDATE CASCADE ON UPDATE CASCADE
); );
@ -73,36 +76,35 @@ CREATE TYPE "ClassType" AS ENUM (
CREATE TABLE "Class" ( CREATE TABLE "Class" (
begin_date timestamptz, begin_date timestamptz,
"Course_id" int, course_id int,
"Studio_id" int, PRIMARY KEY (begin_date, course_id),
studio_id int,
name text NOT NULL, name text NOT NULL,
type "ClassType" NOT NULL, type "ClassType" NOT NULL,
duration interval NOT NULL, duration interval NOT NULL,
PRIMARY KEY (begin_date, "Course_id"), FOREIGN KEY (course_id) REFERENCES "Course" (course_id)
FOREIGN KEY ("Course_id") REFERENCES "Course" (id)
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE, ON UPDATE CASCADE,
FOREIGN KEY ("Studio_id") REFERENCES "Studio" (id) FOREIGN KEY (studio_id) REFERENCES "Studio" (studio_id)
ON DELETE SET NULL ON DELETE SET NULL
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE TABLE "Class_Master" ( CREATE TABLE "Class_Master" (
"Class_begin_date" timestamptz, class_begin_date timestamptz,
"Class_Course_id" int, class_course_id int,
"Master_id" int, master_id int,
PRIMARY KEY (class_begin_date, class_course_id, master_id),
PRIMARY KEY ("Class_begin_date", "Class_Course_id", "Master_id"), FOREIGN KEY (master_id) REFERENCES "Master" (person_id)
FOREIGN KEY ("Master_id") REFERENCES "Master" ("Person_id")
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE, ON UPDATE CASCADE,
FOREIGN KEY ("Class_begin_date", "Class_Course_id") REFERENCES "Class" (begin_date, "Course_id") FOREIGN KEY (class_begin_date, class_course_id) REFERENCES "Class" (begin_date, course_id)
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE ON UPDATE CASCADE
); );
@ -115,138 +117,140 @@ CREATE TYPE "RegistrationStatus" AS ENUM (
CREATE TABLE "Registration" ( CREATE TABLE "Registration" (
"Client_id" int, client_id int,
"Course_id" int, course_id int,
PRIMARY KEY (client_id, course_id),
date timestamptz NOT NULL, date timestamptz NOT NULL,
status "RegistrationStatus" NOT NULL, status "RegistrationStatus" NOT NULL,
PRIMARY KEY ("Client_id", "Course_id"), FOREIGN KEY (client_id) REFERENCES "Client" (person_id)
FOREIGN KEY ("Client_id") REFERENCES "Client" ("Person_id")
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE, ON UPDATE CASCADE,
FOREIGN KEY ("Course_id") REFERENCES "Course" (id) FOREIGN KEY (course_id) REFERENCES "Course" (course_id)
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE TABLE "FoodProductEnum" ( CREATE TABLE "FoodProductEnum" (
id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, food_product_enum_id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name text NOT NULL, name text NOT NULL,
avg_price real NOT NULL avg_price real NOT NULL
); );
CREATE TABLE "FoodProduct" ( CREATE TABLE "FoodProduct" (
id int GENERATED ALWAYS AS IDENTITY, food_product_id int GENERATED ALWAYS AS IDENTITY,
"FoodProductEnum_id" int, food_product_enum_id int,
"Class_begin_date" timestamptz, PRIMARY KEY (food_product_id, food_product_enum_id),
"Class_Course_id" int,
class_begin_date timestamptz,
class_course_id int,
buy_price real NOT NULL, buy_price real NOT NULL,
buy_date timestamptz NOT NULL, buy_date timestamptz NOT NULL,
delivery_price real NOT NULL, delivery_price real NOT NULL,
delivery_date timestamptz NOT NULL, delivery_date timestamptz NOT NULL,
expires_date timestamptz NOT NULL, expires_date timestamptz NOT NULL,
PRIMARY KEY (id, "FoodProductEnum_id"), FOREIGN KEY (food_product_enum_id) REFERENCES "FoodProductEnum" (food_product_enum_id)
FOREIGN KEY ("FoodProductEnum_id") REFERENCES "FoodProductEnum" (id)
ON DELETE RESTRICT ON DELETE RESTRICT
ON UPDATE RESTRICT, ON UPDATE RESTRICT,
FOREIGN KEY ("Class_begin_date", "Class_Course_id") REFERENCES "Class" (begin_date, "Course_id") FOREIGN KEY (class_begin_date, class_course_id) REFERENCES "Class" (begin_date, course_id)
ON DELETE SET NULL ON DELETE SET NULL
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE TABLE "Equipment" ( CREATE TABLE "Equipment" (
id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, equipment_id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
"Studio_id" int,
studio_id int,
name text NOT NULL, name text NOT NULL,
usage_price real NOT NULL, usage_price real NOT NULL,
usage_type "UsageType" NOT NULL, usage_type "UsageType" NOT NULL,
delivery_price real NOT NULL, delivery_price real NOT NULL,
delivery_date timestamptz NOT NULL, delivery_date timestamptz NOT NULL,
FOREIGN KEY ("Studio_id") REFERENCES "Studio" (id) FOREIGN KEY (studio_id) REFERENCES "Studio" (studio_id)
ON DELETE SET NULL ON DELETE SET NULL
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE TABLE "Class_Equipment" ( CREATE TABLE "Class_Equipment" (
"Class_begin_date" timestamptz, class_begin_date timestamptz,
"Class_Course_id" int, class_course_id int,
"Equipment_id" int, equipment_id int,
PRIMARY KEY (class_begin_date, class_course_id, equipment_id),
PRIMARY KEY ("Class_begin_date", "Class_Course_id", "Equipment_id"), FOREIGN KEY (class_begin_date, class_course_id) REFERENCES "Class" (begin_date, course_id)
FOREIGN KEY ("Class_begin_date", "Class_Course_id") REFERENCES "Class" (begin_date, "Course_id")
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE, ON UPDATE CASCADE,
FOREIGN KEY ("Equipment_id") REFERENCES "Equipment" (id) FOREIGN KEY (equipment_id) REFERENCES "Equipment" (equipment_id)
ON DELETE RESTRICT ON DELETE RESTRICT
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE TABLE "DrugEnum" ( CREATE TABLE "DrugEnum" (
id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, drug_enum_id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name text NOT NULL, name text NOT NULL,
avg_price real NOT NULL avg_price real NOT NULL
); );
CREATE TABLE "Drug" ( CREATE TABLE "Drug" (
id int GENERATED ALWAYS AS IDENTITY, drug_id int GENERATED ALWAYS AS IDENTITY,
"DrugEnum_id" int, drug_enum_id int,
"Course_id" int, PRIMARY KEY (drug_id, drug_enum_id),
course_id int,
buy_price real NOT NULL, buy_price real NOT NULL,
buy_date timestamptz NOT NULL, buy_date timestamptz NOT NULL,
delivery_price real NOT NULL, delivery_price real NOT NULL,
delivery_date timestamptz NOT NULL, delivery_date timestamptz NOT NULL,
expires_date timestamptz NOT NULL, expires_date timestamptz NOT NULL,
PRIMARY KEY (id, "DrugEnum_id"), FOREIGN KEY (drug_enum_id) REFERENCES "DrugEnum" (drug_enum_id)
FOREIGN KEY ("DrugEnum_id") REFERENCES "DrugEnum" (id)
ON DELETE RESTRICT ON DELETE RESTRICT
ON UPDATE RESTRICT, ON UPDATE RESTRICT,
FOREIGN KEY ("Course_id") REFERENCES "Course" (id) FOREIGN KEY (course_id) REFERENCES "Course" (course_id)
ON DELETE SET NULL ON DELETE SET NULL
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE TABLE "DrugIntolerance" ( CREATE TABLE "DrugIntolerance" (
"Person_id" int, person_id int,
"DrugEnum_id" int, drug_enum_id int,
PRIMARY KEY ("Person_id", "DrugEnum_id"), PRIMARY KEY (person_id, drug_enum_id),
FOREIGN KEY ("Person_id") REFERENCES "Person" (id) FOREIGN KEY (person_id) REFERENCES "Person" (person_id)
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE, ON UPDATE CASCADE,
FOREIGN KEY ("DrugEnum_id") REFERENCES "DrugEnum" (id) FOREIGN KEY (drug_enum_id) REFERENCES "DrugEnum" (drug_enum_id)
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE TABLE "ActivityLog" ( CREATE TABLE "ActivityLog" (
id int GENERATED ALWAYS AS IDENTITY, activity_log_id int GENERATED ALWAYS AS IDENTITY,
"Person_id" int, person_id int,
PRIMARY KEY (activity_log_id, person_id),
action text NOT NULL, action text NOT NULL,
PRIMARY KEY (id, "Person_id"), FOREIGN KEY (person_id) REFERENCES "Person" (person_id)
FOREIGN KEY ("Person_id") REFERENCES "Person" (id)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE CASCADE ON UPDATE CASCADE
); );