2022-02-10 07:43:47 +00:00
|
|
|
/*
|
|
|
|
Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
|
|
|
|
Copyright (C) 2022 Dominic Grimm
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2022-01-08 12:29:22 +00:00
|
|
|
-- +micrate Up
|
2022-02-10 07:43:47 +00:00
|
|
|
-- SQL in section ' Up ' is executed when this migration is applied
|
2022-02-13 20:54:04 +00:00
|
|
|
CREATE TYPE user_roles AS ENUM ('Teacher', 'Student');
|
2022-02-05 13:40:51 +00:00
|
|
|
|
|
|
|
CREATE TABLE users(
|
|
|
|
id BIGSERIAL PRIMARY KEY,
|
2022-02-06 15:42:08 +00:00
|
|
|
username TEXT UNIQUE NOT NULL,
|
2022-02-05 13:40:51 +00:00
|
|
|
role user_roles NOT NULL,
|
2022-02-06 15:42:08 +00:00
|
|
|
admin BOOLEAN NOT NULL
|
2022-01-08 12:29:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE teachers(
|
|
|
|
id BIGSERIAL PRIMARY KEY,
|
|
|
|
user_id BIGINT NOT NULL UNIQUE REFERENCES users(id),
|
2022-01-20 16:30:20 +00:00
|
|
|
max_students INT NOT NULL,
|
|
|
|
skif BOOLEAN NOT NULL
|
2022-01-08 12:29:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE students(
|
|
|
|
id BIGSERIAL PRIMARY KEY,
|
|
|
|
user_id BIGINT NOT NULL UNIQUE REFERENCES users(id),
|
|
|
|
skif BOOLEAN NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
ALTER TABLE
|
|
|
|
users
|
|
|
|
ADD
|
|
|
|
COLUMN teacher_id BIGINT UNIQUE REFERENCES teachers(id);
|
|
|
|
|
|
|
|
ALTER TABLE
|
|
|
|
users
|
|
|
|
ADD
|
|
|
|
COLUMN student_id BIGINT UNIQUE REFERENCES students(id);
|
|
|
|
|
2022-02-05 13:40:51 +00:00
|
|
|
CREATE TABLE votes(
|
|
|
|
id BIGSERIAL PRIMARY KEY,
|
|
|
|
student_id BIGINT NOT NULL UNIQUE REFERENCES students(id)
|
|
|
|
);
|
2022-01-08 12:29:22 +00:00
|
|
|
|
2022-01-20 16:30:20 +00:00
|
|
|
ALTER TABLE
|
2022-02-05 13:40:51 +00:00
|
|
|
students
|
|
|
|
ADD
|
|
|
|
COLUMN vote_id BIGINT UNIQUE REFERENCES votes(id);
|
2022-01-08 12:29:22 +00:00
|
|
|
|
2022-02-05 13:40:51 +00:00
|
|
|
CREATE TABLE teacher_votes(
|
|
|
|
id BIGSERIAL PRIMARY KEY,
|
|
|
|
vote_id BIGINT NOT NULL REFERENCES votes(id),
|
|
|
|
teacher_id BIGINT NOT NULL REFERENCES teachers(id),
|
|
|
|
priority INT NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
-- +micrate Down
|
2022-02-10 07:43:47 +00:00
|
|
|
-- SQL section ' Down ' is executed when this migration is rolled back
|
2022-02-05 13:40:51 +00:00
|
|
|
DROP TABLE teacher_votes;
|
|
|
|
|
|
|
|
DROP TABLE votes;
|
2022-01-08 12:29:22 +00:00
|
|
|
|
|
|
|
DROP TABLE admins;
|
|
|
|
|
|
|
|
DROP TABLE teachers;
|
|
|
|
|
2022-02-05 13:40:51 +00:00
|
|
|
DROP TABLE students;
|
|
|
|
|
|
|
|
DROP TABLE users;
|
|
|
|
|
|
|
|
DROP TYPE user_roles;
|