This commit is contained in:
Dominic Grimm 2023-02-22 18:02:10 +01:00
parent 027aad58f9
commit 7f3cf3b2b5
No known key found for this signature in database
GPG key ID: 6F294212DEAAC530
11 changed files with 55 additions and 710 deletions

View file

@ -2,30 +2,32 @@ CREATE TABLE schoolyears (
id SERIAL PRIMARY KEY,
untis_id INTEGER NOT NULL UNIQUE,
name VARCHAR NOT NULL,
start_date DATE NOT NULL,
end_date DATE NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE UNIQUE INDEX schoolyears_unique ON schoolyears(active)
WHERE
active;
CREATE TABLE tenants (
id SERIAL PRIMARY KEY,
untis_id INTEGER NOT NULL UNIQUE,
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears (id),
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
name VARCHAR NOT NULL,
active BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE UNIQUE INDEX tenants_active ON tenants (active)
CREATE UNIQUE INDEX tenants_active ON tenants(active)
WHERE
active;
CREATE TABLE teachers (
id SERIAL PRIMARY KEY,
untis_id INTEGER NOT NULL UNIQUE,
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears (id),
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
name VARCHAR NOT NULL,
forename VARCHAR,
display_name VARCHAR NOT NULL,
@ -36,7 +38,7 @@ CREATE TABLE teachers (
CREATE TABLE classes (
id SERIAL PRIMARY KEY,
untis_id INTEGER NOT NULL UNIQUE,
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears (id),
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
name VARCHAR NOT NULL,
long_name VARCHAR NOT NULL,
active BOOLEAN NOT NULL,
@ -47,7 +49,7 @@ CREATE TABLE classes (
CREATE TABLE subjects (
id SERIAL PRIMARY KEY,
untis_id INTEGER NOT NULL UNIQUE,
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears (id),
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
name VARCHAR NOT NULL,
long_name VARCHAR NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@ -57,7 +59,7 @@ CREATE TABLE subjects (
CREATE TABLE rooms (
id SERIAL PRIMARY KEY,
untis_id INTEGER NOT NULL UNIQUE,
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears (id),
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
name VARCHAR NOT NULL,
long_name VARCHAR NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@ -67,7 +69,7 @@ CREATE TABLE rooms (
CREATE TABLE departments (
id SERIAL PRIMARY KEY,
untis_id INTEGER NOT NULL UNIQUE,
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears (id),
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
name VARCHAR NOT NULL,
long_name VARCHAR NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@ -77,7 +79,7 @@ CREATE TABLE departments (
CREATE TABLE holidays (
id SERIAL PRIMARY KEY,
untis_id INTEGER NOT NULL UNIQUE,
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears (id),
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
name VARCHAR NOT NULL,
long_name VARCHAR NOT NULL,
start_date DATE NOT NULL,
@ -88,14 +90,14 @@ CREATE TABLE holidays (
CREATE TABLE timegrids (
id SERIAL PRIMARY KEY,
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears (id),
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE TABLE timegrid_days (
id SERIAL PRIMARY KEY,
timegrid_id INTEGER NOT NULL REFERENCES timegrids (id),
timegrid_id INTEGER NOT NULL REFERENCES timegrids(id),
day_index SMALLINT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
@ -103,7 +105,7 @@ CREATE TABLE timegrid_days (
CREATE TABLE timegrid_time_unit (
id SERIAL PRIMARY KEY,
timegrid_day_id INTEGER NOT NULL REFERENCES timegrid_days (id),
timegrid_day_id INTEGER NOT NULL REFERENCES timegrid_days(id),
start_time TIME NOT NULL,
end_time TIME NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@ -114,7 +116,7 @@ CREATE TYPE week_type AS ENUM ('a', 'b');
CREATE TABLE substitution_queries (
id SERIAL PRIMARY KEY,
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears (id),
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
date DATE NOT NULL,
week_type week_type NOT NULL,
queried_at TIMESTAMP NOT NULL,
@ -142,7 +144,7 @@ CREATE TYPE substitution_type AS ENUM (
CREATE TABLE substitutions(
id SERIAL PRIMARY KEY,
substitution_query_id INTEGER NOT NULL REFERENCES substitution_queries (id),
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,
@ -154,37 +156,37 @@ CREATE TABLE substitutions(
CREATE TABLE substitution_classes (
id SERIAL PRIMARY KEY,
substitution_id INTEGER NOT NULL REFERENCES substitutions (id),
substitution_id INTEGER NOT NULL REFERENCES substitutions(id),
position SMALLINT NOT NULL,
class_id INTEGER NOT NULL REFERENCES classes (id),
class_id INTEGER NOT NULL REFERENCES classes(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE TABLE substitution_teachers (
id SERIAL PRIMARY KEY,
substitution_id INTEGER NOT NULL REFERENCES substitutions (id),
substitution_id INTEGER NOT NULL REFERENCES substitutions(id),
position SMALLINT NOT NULL,
teacher_id INTEGER REFERENCES teachers (id),
teacher_id INTEGER REFERENCES teachers(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE TABLE substitution_subjects (
id SERIAL PRIMARY KEY,
substitution_id INTEGER NOT NULL REFERENCES substitutions (id),
substitution_id INTEGER NOT NULL REFERENCES substitutions(id),
position SMALLINT NOT NULL,
subject_id INTEGER NOT NULL REFERENCES subjects (id),
subject_id INTEGER NOT NULL REFERENCES subjects(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE TABLE substitution_rooms (
id SERIAL PRIMARY KEY,
substitution_id INTEGER NOT NULL REFERENCES substitutions (id),
substitution_id INTEGER NOT NULL REFERENCES substitutions(id),
position SMALLINT NOT NULL,
room_id INTEGER REFERENCES rooms (id),
original_room_id INTEGER REFERENCES rooms (id),
room_id INTEGER REFERENCES rooms(id),
original_room_id INTEGER REFERENCES rooms(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);