Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Vyacheslav1557 2024-08-16 18:08:00 +05:00
commit 285b600b3f

View file

@ -18,6 +18,7 @@ CREATE TABLE IF NOT EXISTS languages
CREATE TABLE IF NOT EXISTS problems
(
id serial NOT NULL,
is_uploaded BOOLEAN NOT NULL,
name VARCHAR(300) NOT NULL,
description TEXT 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 (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();