add problem upload flag

This commit is contained in:
dragonmuffin 2024-08-16 17:24:37 +05:00
parent 9f48553f67
commit 1fad85d394

View file

@ -18,6 +18,7 @@ CREATE TABLE IF NOT EXISTS languages
CREATE TABLE IF NOT EXISTS problems CREATE TABLE IF NOT EXISTS problems
( (
id serial NOT NULL, id serial NOT NULL,
is_uploaded BOOLEAN NOT NULL,
name VARCHAR(300) NOT NULL, name VARCHAR(300) NOT NULL,
description TEXT NOT NULL, description TEXT NOT NULL,
time_limit INT NOT NULL, time_limit INT NOT NULL,
@ -65,6 +66,16 @@ CREATE INDEX ON tasks USING BTREE (id);
CREATE INDEX ON tasks USING BTREE (contest_id); CREATE INDEX ON tasks USING BTREE (contest_id);
CREATE INDEX ON tasks USING BTREE (problem_id); CREATE INDEX ON tasks USING BTREE (problem_id);
CREATE FUNCTION check_problem_uploaded() RETURNS TRIGGER
LANGUAGE plpgsql AS $$ BEGIN
IF NOT EXISTS (SELECT (id) FROM problems WHERE id=NEW.problem_id AND is_uploaded=TRUE) THEN
RAISE EXCEPTION 'trying to add not uploaded problem';
END IF;
RETURN NEW;
END;$$;
CREATE TRIGGER check_problem_uploaded_trg BEFORE INSERT ON tasks FOR EACH ROW EXECUTE FUNCTION check_problem_uploaded();