2024-07-27 09:27:14 +00:00
|
|
|
-- +goose Up
|
|
|
|
-- +goose StatementBegin
|
2024-08-14 08:35:36 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS problems
|
|
|
|
(
|
2024-10-16 19:34:43 +00:00
|
|
|
id serial NOT NULL,
|
|
|
|
title varchar(64) NOT NULL,
|
|
|
|
legend varchar(10240) NOT NULL DEFAULT '',
|
|
|
|
input_format varchar(10240) NOT NULL DEFAULT '',
|
|
|
|
output_format varchar(10240) NOT NULL DEFAULT '',
|
|
|
|
notes varchar(10240) NOT NULL DEFAULT '',
|
|
|
|
tutorial varchar(10240) NOT NULL DEFAULT '',
|
|
|
|
latex_summary varchar(10240) NOT NULL DEFAULT '',
|
|
|
|
time_limit integer NOT NULL DEFAULT 1000,
|
2024-10-16 19:48:38 +00:00
|
|
|
memory_limit integer NOT NULL DEFAULT 64,
|
2024-10-16 19:34:43 +00:00
|
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
2024-10-13 14:01:36 +00:00
|
|
|
PRIMARY KEY (id),
|
|
|
|
CHECK (length(title) != 0),
|
2024-10-16 19:48:38 +00:00
|
|
|
CHECK (memory_limit BETWEEN 4 and 1024),
|
|
|
|
CHECK (time_limit BETWEEN 250 and 15000)
|
2024-08-14 08:35:36 +00:00
|
|
|
);
|
|
|
|
|
2024-10-13 14:01:36 +00:00
|
|
|
CREATE TRIGGER on_problems_update
|
|
|
|
BEFORE UPDATE
|
|
|
|
ON problems
|
|
|
|
FOR EACH ROW
|
|
|
|
EXECUTE PROCEDURE updated_at_update();
|
2024-08-14 08:35:36 +00:00
|
|
|
|
2024-08-14 11:04:30 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS contests
|
|
|
|
(
|
2024-10-16 19:34:43 +00:00
|
|
|
id serial NOT NULL,
|
|
|
|
title varchar(64) NOT NULL,
|
|
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
2024-10-13 14:01:36 +00:00
|
|
|
PRIMARY KEY (id),
|
|
|
|
CHECK (length(title) != 0)
|
2024-08-14 11:04:30 +00:00
|
|
|
);
|
|
|
|
|
2024-10-13 14:01:36 +00:00
|
|
|
CREATE TRIGGER on_contests_update
|
|
|
|
BEFORE UPDATE
|
|
|
|
ON contests
|
|
|
|
FOR EACH ROW
|
|
|
|
EXECUTE PROCEDURE updated_at_update();
|
2024-08-14 11:04:30 +00:00
|
|
|
|
2024-08-15 14:08:05 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS tasks
|
2024-08-14 11:04:30 +00:00
|
|
|
(
|
2024-10-13 14:01:36 +00:00
|
|
|
id serial NOT NULL,
|
|
|
|
problem_id integer NOT NULL REFERENCES problems (id),
|
|
|
|
contest_id integer NOT NULL REFERENCES contests (id),
|
|
|
|
position integer NOT NULL,
|
|
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
UNIQUE (problem_id, contest_id),
|
2024-10-16 19:34:43 +00:00
|
|
|
UNIQUE (contest_id, position),
|
2024-10-13 14:01:36 +00:00
|
|
|
CHECK (position >= 0)
|
2024-08-14 11:04:30 +00:00
|
|
|
);
|
|
|
|
|
2024-10-13 14:01:36 +00:00
|
|
|
CREATE TRIGGER on_tasks_update
|
|
|
|
BEFORE UPDATE
|
|
|
|
ON tasks
|
|
|
|
FOR EACH ROW
|
|
|
|
EXECUTE PROCEDURE updated_at_update();
|
2024-08-15 14:08:05 +00:00
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS participants
|
|
|
|
(
|
2024-10-16 19:34:43 +00:00
|
|
|
id serial NOT NULL,
|
|
|
|
user_id integer NOT NULL,
|
|
|
|
contest_id integer NOT NULL REFERENCES contests (id),
|
|
|
|
name varchar(64) NOT NULL,
|
|
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
2024-10-13 14:01:36 +00:00
|
|
|
PRIMARY KEY (id),
|
|
|
|
UNIQUE (user_id, contest_id),
|
|
|
|
CHECK (length(name) != 0)
|
2024-08-14 08:35:36 +00:00
|
|
|
);
|
|
|
|
|
2024-10-13 14:01:36 +00:00
|
|
|
CREATE TRIGGER on_participants_update
|
|
|
|
BEFORE UPDATE
|
|
|
|
ON participants
|
|
|
|
FOR EACH ROW
|
|
|
|
EXECUTE PROCEDURE updated_at_update();
|
2024-08-14 08:35:36 +00:00
|
|
|
|
2024-07-27 09:27:14 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS solutions
|
|
|
|
(
|
2024-10-13 14:01:36 +00:00
|
|
|
id serial NOT NULL,
|
|
|
|
task_id integer NOT NULL REFERENCES tasks (id),
|
|
|
|
participant_id integer NOT NULL REFERENCES participants (id),
|
|
|
|
solution varchar(1048576) NOT NULL,
|
|
|
|
state integer NOT NULL DEFAULT 1,
|
|
|
|
score integer NOT NULL,
|
|
|
|
penalty integer NOT NULL,
|
|
|
|
total_score integer NOT NULL,
|
|
|
|
language integer NOT NULL,
|
|
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
2024-08-14 08:35:36 +00:00
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
2024-10-13 14:01:36 +00:00
|
|
|
CREATE TRIGGER on_solutions_update
|
|
|
|
BEFORE UPDATE
|
|
|
|
ON solutions
|
|
|
|
FOR EACH ROW
|
|
|
|
EXECUTE PROCEDURE updated_at_update();
|
2024-08-17 13:00:34 +00:00
|
|
|
|
2024-08-16 11:26:04 +00:00
|
|
|
CREATE FUNCTION updated_at_update() RETURNS TRIGGER
|
|
|
|
LANGUAGE plpgsql AS
|
|
|
|
$$
|
|
|
|
BEGIN
|
|
|
|
NEW.updated_at = NOW();
|
|
|
|
RETURN NEW;
|
|
|
|
END;
|
|
|
|
$$;
|
|
|
|
|
2024-07-27 09:27:14 +00:00
|
|
|
-- +goose StatementEnd
|
|
|
|
|
|
|
|
-- +goose Down
|
2024-08-14 15:19:44 +00:00
|
|
|
-- +goose StatementBegin
|
2024-10-13 14:01:36 +00:00
|
|
|
DROP TRIGGER IF EXISTS on_problems_update ON problems;
|
|
|
|
DROP TABLE IF EXISTS problems;
|
|
|
|
DROP TRIGGER IF EXISTS on_contests_update ON contests;
|
|
|
|
DROP TABLE IF EXISTS contests;
|
|
|
|
DROP TRIGGER IF EXISTS on_tasks_update ON tasks;
|
|
|
|
DROP TABLE IF EXISTS tasks;
|
|
|
|
DROP TRIGGER IF EXISTS on_participants_update ON participants;
|
|
|
|
DROP TABLE IF EXISTS participants;
|
|
|
|
DROP TRIGGER IF EXISTS on_solutions_update ON solutions;
|
|
|
|
DROP TABLE IF EXISTS solutions;
|
|
|
|
DROP FUNCTION updated_at_update();
|
2024-08-14 15:19:44 +00:00
|
|
|
-- +goose StatementEnd
|