4 deleted inheritance, course deadline_date
This commit is contained in:
23
4/data.js
23
4/data.js
@ -150,9 +150,9 @@ const ClassTypes = ['Theory', 'Practice']
|
||||
const RegistrationStatuses = ['NotPaid', 'Paid']
|
||||
const EquipmentUsageTypes = ['PayOnce', 'PayMonthly']
|
||||
|
||||
function Values(callback) {
|
||||
function Values(callback, factor = 1) {
|
||||
let res = 'VALUES\n'
|
||||
const count = 5
|
||||
const count = 5 * factor
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
res += callback()
|
||||
@ -167,14 +167,21 @@ function Values(callback) {
|
||||
}
|
||||
|
||||
|
||||
// Person
|
||||
let script = 'INSERT INTO "Person" (full_name, passwd_hash) ' + Values(() => {
|
||||
return `(${GenFullName()}, ${GenPasswdHash()})`
|
||||
}, 2)
|
||||
|
||||
let person_id = 1
|
||||
|
||||
// Master
|
||||
let script = 'INSERT INTO "Master" (full_name, passwd_hash, passport, readme) ' + Values(() => {
|
||||
return `(${GenFullName()}, ${GenPasswdHash()}, ${GenPassport()}, 'aboba')`
|
||||
script += 'INSERT INTO "Master" ("Person_id", passport, readme) ' + Values(() => {
|
||||
return `(${person_id++}, ${GenPassport()}, 'aboba')`
|
||||
})
|
||||
|
||||
// Client
|
||||
script += 'INSERT INTO "Client" (full_name, passwd_hash, phone, email, billing_account) ' + Values(() => {
|
||||
return `(${GenFullName()}, ${GenPasswdHash()}, ${GenPassport()}, ${GenPhone()}, ${GenBillingAccount()})`
|
||||
script += 'INSERT INTO "Client" ("Person_id", phone, email, billing_account) ' + Values(() => {
|
||||
return `(${person_id++}, ${GenPhone()}, ${GenEmail()}, ${GenBillingAccount()})`
|
||||
})
|
||||
|
||||
// Studio
|
||||
@ -183,8 +190,8 @@ script += 'INSERT INTO "Studio" (address, capacity, begin_date, duration) ' + Va
|
||||
})
|
||||
|
||||
// Course
|
||||
script += 'INSERT INTO "Course" ("Master_id", name, price, duration) ' + Values(() => {
|
||||
return `(${GenInt(1, 6)}, 'курс ${GenMaxUInt(100)}', ${GenPrice()}, ${GenIntervalHours(20)})`
|
||||
script += 'INSERT INTO "Course" ("Master_id", name, price, deadline_date) ' + Values(() => {
|
||||
return `(${GenInt(1, 6)}, 'курс ${GenMaxUInt(3)}', ${GenPrice()}, ${GenTimestamp()})`
|
||||
})
|
||||
|
||||
// Class
|
||||
|
||||
39
4/schema.sql
39
4/schema.sql
@ -1,39 +1,40 @@
|
||||
DROP TABLE IF EXISTS "Person" CASCADE;
|
||||
DROP SEQUENCE IF EXISTS "PersonId";
|
||||
DROP TABLE IF EXISTS "Person", "Client", "Master", "Studio", "Course", "Class", "Class_Master", "Registration", "FoodProductEnum", "FoodProduct", "Equipment", "Class_Equipment", "DrugEnum", "Drug", "DrugIntolerance", "ActivityLog";
|
||||
|
||||
|
||||
CREATE SEQUENCE "PersonId";
|
||||
DROP TYPE IF EXISTS "ClassType", "RegistrationStatus", "EquipmentUsageType";
|
||||
|
||||
|
||||
CREATE TABLE "Person" (
|
||||
id int PRIMARY KEY DEFAULT nextval('"PersonId"'),
|
||||
id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
full_name text NOT NULL,
|
||||
passwd_hash bytea NOT NULL
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE "Client" (
|
||||
"Person_id" int UNIQUE NOT NULL,
|
||||
|
||||
phone text NOT NULL,
|
||||
email text NOT NULL,
|
||||
billing_account text NOT NULL,
|
||||
|
||||
PRIMARY KEY (id)
|
||||
) INHERITS ("Person");
|
||||
|
||||
FOREIGN KEY ("Person_id") REFERENCES "Person" (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE "Master" (
|
||||
"Person_id" int UNIQUE NOT NULL,
|
||||
|
||||
passport text UNIQUE NOT NULL,
|
||||
readme text NOT NULL,
|
||||
|
||||
PRIMARY KEY (id)
|
||||
) INHERITS ("Person");
|
||||
FOREIGN KEY ("Person_id") REFERENCES "Person" (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS "Studio", "Course", "Class", "Class_Master", "Registration", "FoodProductEnum", "FoodProduct", "Equipment", "Class_Equipment", "DrugEnum", "Drug", "DrugIntolerance", "ActivityLog";
|
||||
|
||||
|
||||
DROP TYPE IF EXISTS "ClassType", "RegistrationStatus", "EquipmentUsageType";
|
||||
|
||||
CREATE TABLE "Studio" (
|
||||
id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
address text UNIQUE NOT NULL,
|
||||
@ -48,9 +49,9 @@ CREATE TABLE "Course" (
|
||||
"Master_id" int,
|
||||
name text NOT NULL,
|
||||
price real NOT NULL CHECK (price > 0),
|
||||
duration interval NOT NULL,
|
||||
deadline_date timestamptz NOT NULL,
|
||||
|
||||
FOREIGN KEY ("Master_id") REFERENCES "Master" (id)
|
||||
FOREIGN KEY ("Master_id") REFERENCES "Master" ("Person_id")
|
||||
ON DELETE SET NULL
|
||||
ON UPDATE CASCADE
|
||||
);
|
||||
@ -89,7 +90,7 @@ CREATE TABLE "Class_Master" (
|
||||
|
||||
PRIMARY KEY ("Class_begin_date", "Class_Course_id", "Master_id"),
|
||||
|
||||
FOREIGN KEY ("Master_id") REFERENCES "Master" (id)
|
||||
FOREIGN KEY ("Master_id") REFERENCES "Master" ("Person_id")
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
|
||||
@ -113,7 +114,7 @@ CREATE TABLE "Registration" (
|
||||
|
||||
PRIMARY KEY ("Client_id", "Course_id"),
|
||||
|
||||
FOREIGN KEY ("Client_id") REFERENCES "Client" (id)
|
||||
FOREIGN KEY ("Client_id") REFERENCES "Client" ("Person_id")
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user