studium/db/migrations/20261024120000_users.sql
Antoine Pelletier ce985ef784
Some checks failed
build / image (push) Failing after 31s
wip
2026-10-24 12:55:18 +02:00

25 lines
1.2 KiB
SQL

-- migrate:up
-- Each person has their own courses, associations and calendars: they are owned by the
-- login given by Authelia (`Remote-User`). Everything else (slots, grades, tasks,
-- files, events) belongs to the owner of its course or calendar. The tags stay shared.
-- What existed before is given to the first user of the app.
ALTER TABLE courses ADD COLUMN "owner" TEXT;
UPDATE courses SET "owner" = 'appellet';
ALTER TABLE courses ALTER COLUMN "owner" SET NOT NULL;
-- The folders are in the folder of their owner in the storage: two people may have the
-- same course
ALTER TABLE courses DROP CONSTRAINT courses_folder_key;
ALTER TABLE courses ADD CONSTRAINT courses_owner_folder_key UNIQUE ("owner", folder);
ALTER TABLE calendars ADD COLUMN "owner" TEXT;
UPDATE calendars SET "owner" = 'appellet';
ALTER TABLE calendars ALTER COLUMN "owner" SET NOT NULL;
CREATE INDEX calendars_owner_idx ON calendars ("owner");
-- migrate:down
DROP INDEX IF EXISTS calendars_owner_idx;
ALTER TABLE calendars DROP COLUMN "owner";
ALTER TABLE courses DROP CONSTRAINT courses_owner_folder_key;
ALTER TABLE courses ADD CONSTRAINT courses_folder_key UNIQUE (folder);
ALTER TABLE courses DROP COLUMN "owner";