This commit is contained in:
Dominic Grimm 2022-12-14 19:13:32 +01:00
parent 2b65b6a1c5
commit f13c9c905f
No known key found for this signature in database
GPG key ID: 6F294212DEAAC530
15 changed files with 322 additions and 981 deletions

View file

@ -1,9 +1,3 @@
DROP TABLE substitution_query_results;
DROP TABLE substitution_queries;
DROP TABLE substitution_planned_queries;
DROP TABLE substitution_room;
DROP TABLE substitution_subject;
@ -16,6 +10,8 @@ DROP TABLE substitutions;
DROP TYPE substitution_type;
DROP TABLE substitution_queries;
DROP TABLE timegrid_time_unit;
DROP TABLE timegrid_days;
@ -34,6 +30,8 @@ DROP TABLE classes;
DROP TABLE teachers;
DROP INDEX tenants_active;
DROP TABLE tenants;
DROP TABLE schoolyears;

View file

@ -18,7 +18,7 @@ CREATE TABLE tenants(
updated_at TIMESTAMP
);
CREATE UNIQUE INDEX ON tenants(active)
CREATE UNIQUE INDEX tenants_active ON tenants(active)
WHERE
active;
@ -110,6 +110,17 @@ CREATE TABLE timegrid_time_unit(
updated_at TIMESTAMP
);
CREATE TABLE substitution_queries(
id SERIAL PRIMARY KEY,
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
date DATE NOT NULL UNIQUE,
active BOOLEAN NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE INDEX substitution_queries_active ON substitution_queries(active);
CREATE TYPE substitution_type AS ENUM (
'cancel',
'subst',
@ -130,6 +141,7 @@ CREATE TYPE substitution_type AS ENUM (
CREATE TABLE substitutions(
id SERIAL PRIMARY KEY,
substitution_query_id INTEGER NOT NULL REFERENCES substitution_queries(id),
subst_type substitution_type NOT NULL,
lesson_id INTEGER NOT NULL,
start_time TIME NOT NULL,
@ -142,6 +154,7 @@ CREATE TABLE substitutions(
CREATE TABLE substitution_classes(
id SERIAL PRIMARY KEY,
substitution_id INTEGER NOT NULL REFERENCES substitutions(id),
position SMALLINT NOT NULL,
class_id INTEGER NOT NULL REFERENCES classes(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
@ -150,7 +163,8 @@ CREATE TABLE substitution_classes(
CREATE TABLE substitution_teachers(
id SERIAL PRIMARY KEY,
substitution_id INTEGER NOT NULL REFERENCES substitutions(id),
teacher_id INTEGER NOT NULL REFERENCES teachers(id),
position SMALLINT NOT NULL,
teacher_id INTEGER REFERENCES teachers(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
@ -158,6 +172,7 @@ CREATE TABLE substitution_teachers(
CREATE TABLE substitution_subjects(
id SERIAL PRIMARY KEY,
substitution_id INTEGER NOT NULL REFERENCES substitutions(id),
position SMALLINT NOT NULL,
subject_id INTEGER NOT NULL REFERENCES subjects(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
@ -166,34 +181,8 @@ CREATE TABLE substitution_subjects(
CREATE TABLE substitution_rooms(
id SERIAL PRIMARY KEY,
substitution_id INTEGER NOT NULL REFERENCES substitutions(id),
room_id INTEGER NOT NULL REFERENCES rooms(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE TABLE substitution_planned_queries(
id SERIAL PRIMARY KEY,
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
date DATE NOT NULL UNIQUE,
active BOOLEAN NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE INDEX ON substitution_planned_queries(active);
CREATE TABLE substitution_queries(
id SERIAL PRIMARY KEY,
substitution_planned_query_id INTEGER NOT NULL REFERENCES substitution_planned_queries(id),
queried_at TIMESTAMP NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE TABLE substitution_query_results(
id SERIAL PRIMARY KEY,
substitution_query_id INTEGER NOT NULL REFERENCES substitution_queries(id),
substitution_id INTEGER NOT NULL REFERENCES substitutions(id),
position SMALLINT NOT NULL,
room_id INTEGER REFERENCES rooms(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);