feat: extend problem fields
This commit is contained in:
parent
3ed195bb58
commit
6dc8f05675
14 changed files with 70 additions and 362 deletions
|
@ -2,20 +2,22 @@
|
|||
-- +goose StatementBegin
|
||||
CREATE TABLE IF NOT EXISTS problems
|
||||
(
|
||||
id serial NOT NULL,
|
||||
title varchar(255) NOT NULL,
|
||||
content varchar(65536) NOT NULL DEFAULT '',
|
||||
time_limit integer NOT NULL DEFAULT 1000,
|
||||
memory_limit integer NOT NULL DEFAULT 65536,
|
||||
testing_strategy integer NOT NULL DEFAULT 1,
|
||||
testing_order varchar(1024) NOT NULL DEFAULT '',
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
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,
|
||||
memory_limit integer NOT NULL DEFAULT 65536,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (id),
|
||||
CHECK (length(title) != 0),
|
||||
CHECK (memory_limit > 0),
|
||||
CHECK (time_limit > 0),
|
||||
CHECK (testing_strategy > 0)
|
||||
CHECK (time_limit > 0)
|
||||
);
|
||||
|
||||
CREATE TRIGGER on_problems_update
|
||||
|
@ -26,10 +28,10 @@ EXECUTE PROCEDURE updated_at_update();
|
|||
|
||||
CREATE TABLE IF NOT EXISTS contests
|
||||
(
|
||||
id serial NOT NULL,
|
||||
title varchar(255) NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
id serial NOT NULL,
|
||||
title varchar(64) NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (id),
|
||||
CHECK (length(title) != 0)
|
||||
);
|
||||
|
@ -46,11 +48,11 @@ CREATE TABLE IF NOT EXISTS tasks
|
|||
problem_id integer NOT NULL REFERENCES problems (id),
|
||||
contest_id integer NOT NULL REFERENCES contests (id),
|
||||
position integer NOT NULL,
|
||||
prefix varchar(10) NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE (problem_id, contest_id),
|
||||
UNIQUE (contest_id, position),
|
||||
CHECK (position >= 0)
|
||||
);
|
||||
|
||||
|
@ -62,12 +64,12 @@ EXECUTE PROCEDURE updated_at_update();
|
|||
|
||||
CREATE TABLE IF NOT EXISTS participants
|
||||
(
|
||||
id serial NOT NULL,
|
||||
user_id integer NOT NULL,
|
||||
contest_id integer NOT NULL REFERENCES contests (id),
|
||||
name varchar(255) NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
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(),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE (user_id, contest_id),
|
||||
CHECK (length(name) != 0)
|
||||
|
@ -86,7 +88,6 @@ CREATE TABLE IF NOT EXISTS solutions
|
|||
participant_id integer NOT NULL REFERENCES participants (id),
|
||||
solution varchar(1048576) NOT NULL,
|
||||
state integer NOT NULL DEFAULT 1,
|
||||
results varchar(1000) NOT NULL,
|
||||
score integer NOT NULL,
|
||||
penalty integer NOT NULL,
|
||||
total_score integer NOT NULL,
|
||||
|
@ -102,25 +103,6 @@ CREATE TRIGGER on_solutions_update
|
|||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE updated_at_update();
|
||||
|
||||
CREATE TABLE IF NOT EXISTS best_solutions
|
||||
(
|
||||
id serial NOT NULL,
|
||||
participant_id integer NOT NULL REFERENCES participants (id),
|
||||
task_id integer NOT NULL REFERENCES tasks (id),
|
||||
solution_id integer NOT NULL REFERENCES solutions (id),
|
||||
best_total_score integer NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE (participant_id, task_id)
|
||||
);
|
||||
|
||||
CREATE TRIGGER on_best_solutions_update
|
||||
BEFORE UPDATE
|
||||
ON best_solutions
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE updated_at_update();
|
||||
|
||||
CREATE FUNCTION updated_at_update() RETURNS TRIGGER
|
||||
LANGUAGE plpgsql AS
|
||||
$$
|
||||
|
@ -144,7 +126,5 @@ 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 TRIGGER IF EXISTS on_best_solutions_update ON best_solutions;
|
||||
DROP TABLE IF EXISTS best_solutions;
|
||||
DROP FUNCTION updated_at_update();
|
||||
-- +goose StatementEnd
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue