Compare commits

..

2 commits

Author SHA1 Message Date
dragonmuffin
a09a5594ec Merge remote-tracking branch 'refs/remotes/origin/develop' into develop 2024-08-16 17:25:12 +05:00
dragonmuffin
1fad85d394 add problem upload flag 2024-08-16 17:24:37 +05:00

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();