Init
This commit is contained in:
commit
2b65b6a1c5
26 changed files with 5911 additions and 0 deletions
39
backend/migrations/2022-12-03-124501_init/down.sql
Normal file
39
backend/migrations/2022-12-03-124501_init/down.sql
Normal file
|
@ -0,0 +1,39 @@
|
|||
DROP TABLE substitution_query_results;
|
||||
|
||||
DROP TABLE substitution_queries;
|
||||
|
||||
DROP TABLE substitution_planned_queries;
|
||||
|
||||
DROP TABLE substitution_room;
|
||||
|
||||
DROP TABLE substitution_subject;
|
||||
|
||||
DROP TABLE substitution_teacher;
|
||||
|
||||
DROP TABLE substitution_class;
|
||||
|
||||
DROP TABLE substitutions;
|
||||
|
||||
DROP TYPE substitution_type;
|
||||
|
||||
DROP TABLE timegrid_time_unit;
|
||||
|
||||
DROP TABLE timegrid_days;
|
||||
|
||||
DROP TABLE timegrids;
|
||||
|
||||
DROP TABLE holidays;
|
||||
|
||||
DROP TABLE departments;
|
||||
|
||||
DROP TABLE rooms;
|
||||
|
||||
DROP TABLE subjects;
|
||||
|
||||
DROP TABLE classes;
|
||||
|
||||
DROP TABLE teachers;
|
||||
|
||||
DROP TABLE tenants;
|
||||
|
||||
DROP TABLE schoolyears;
|
199
backend/migrations/2022-12-03-124501_init/up.sql
Normal file
199
backend/migrations/2022-12-03-124501_init/up.sql
Normal file
|
@ -0,0 +1,199 @@
|
|||
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 TABLE tenants(
|
||||
id SERIAL PRIMARY KEY,
|
||||
untis_id INTEGER NOT NULL UNIQUE,
|
||||
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 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),
|
||||
name VARCHAR NOT NULL,
|
||||
forename VARCHAR,
|
||||
display_name VARCHAR NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE classes(
|
||||
id SERIAL PRIMARY KEY,
|
||||
untis_id INTEGER NOT NULL UNIQUE,
|
||||
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
|
||||
name VARCHAR NOT NULL,
|
||||
long_name VARCHAR NOT NULL,
|
||||
active BOOLEAN NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE subjects(
|
||||
id SERIAL PRIMARY KEY,
|
||||
untis_id INTEGER NOT NULL UNIQUE,
|
||||
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,
|
||||
updated_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE rooms(
|
||||
id SERIAL PRIMARY KEY,
|
||||
untis_id INTEGER NOT NULL UNIQUE,
|
||||
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,
|
||||
updated_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE departments(
|
||||
id SERIAL PRIMARY KEY,
|
||||
untis_id INTEGER NOT NULL UNIQUE,
|
||||
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,
|
||||
updated_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE holidays(
|
||||
id SERIAL PRIMARY KEY,
|
||||
untis_id INTEGER NOT NULL UNIQUE,
|
||||
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
|
||||
name VARCHAR NOT NULL,
|
||||
long_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 TABLE timegrids(
|
||||
id SERIAL PRIMARY KEY,
|
||||
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),
|
||||
day_index SMALLINT NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE timegrid_time_unit(
|
||||
id SERIAL PRIMARY KEY,
|
||||
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,
|
||||
updated_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TYPE substitution_type AS ENUM (
|
||||
'cancel',
|
||||
'subst',
|
||||
'add',
|
||||
'shift',
|
||||
'rmchg',
|
||||
'rmlk',
|
||||
'bs',
|
||||
'oh',
|
||||
'sb',
|
||||
'other',
|
||||
'free',
|
||||
'exam',
|
||||
'ac',
|
||||
'holi',
|
||||
'stxt'
|
||||
);
|
||||
|
||||
CREATE TABLE substitutions(
|
||||
id SERIAL PRIMARY KEY,
|
||||
subst_type substitution_type NOT NULL,
|
||||
lesson_id INTEGER NOT NULL,
|
||||
start_time TIME NOT NULL,
|
||||
end_time TIME NOT NULL,
|
||||
text VARCHAR,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE substitution_classes(
|
||||
id SERIAL PRIMARY KEY,
|
||||
substitution_id INTEGER NOT NULL REFERENCES substitutions(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),
|
||||
teacher_id INTEGER NOT NULL 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),
|
||||
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),
|
||||
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),
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue