fix(tester): fix schema&queries
This commit is contained in:
parent
dd87d63860
commit
ffacc9e3ac
2 changed files with 11 additions and 8 deletions
|
@ -67,13 +67,16 @@ func (r *ContestRepository) DeleteContest(ctx context.Context, id int32) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const addTaskQuery = "INSERT INTO tasks (problem_id, contest_id, position) VALUES (?, ?,COALESCE(SELECT MAX(position) FROM task WHERE contest_id = ? ,0) + 1) RETURNING id"
|
const addTaskQuery = `INSERT INTO tasks (problem_id, contest_id, position)
|
||||||
|
VALUES (?, ?, COALESCE((SELECT MAX(position) FROM tasks WHERE contest_id = ?), 0) + 1)
|
||||||
|
RETURNING id
|
||||||
|
`
|
||||||
|
|
||||||
func (r *ContestRepository) AddTask(ctx context.Context, contestId int32, problem_id int32) (int32, error) {
|
func (r *ContestRepository) AddTask(ctx context.Context, contestId int32, problemId int32) (int32, error) {
|
||||||
const op = "ContestRepository.AddTask"
|
const op = "ContestRepository.AddTask"
|
||||||
|
|
||||||
query := r.db.Rebind(addTaskQuery)
|
query := r.db.Rebind(addTaskQuery)
|
||||||
rows, err := r.db.QueryxContext(ctx, query, problem_id, contestId, contestId)
|
rows, err := r.db.QueryxContext(ctx, query, problemId, contestId, contestId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, handlePgErr(err, op)
|
return 0, handlePgErr(err, op)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ CREATE FUNCTION updated_at_update() RETURNS TRIGGER
|
||||||
$$
|
$$
|
||||||
BEGIN
|
BEGIN
|
||||||
NEW.updated_at = NOW();
|
NEW.updated_at = NOW();
|
||||||
RETURN NEW;
|
RETURN NEW;
|
||||||
END;
|
END;
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
|
@ -54,8 +54,8 @@ EXECUTE PROCEDURE updated_at_update();
|
||||||
CREATE TABLE IF NOT EXISTS tasks
|
CREATE TABLE IF NOT EXISTS tasks
|
||||||
(
|
(
|
||||||
id serial NOT NULL,
|
id serial NOT NULL,
|
||||||
problem_id integer NOT NULL REFERENCES problems (id),
|
problem_id integer REFERENCES problems (id) ON DELETE SET NULL,
|
||||||
contest_id integer NOT NULL REFERENCES contests (id),
|
contest_id integer REFERENCES contests (id) ON DELETE SET NULL,
|
||||||
position integer NOT NULL,
|
position integer NOT NULL,
|
||||||
created_at timestamptz NOT NULL DEFAULT now(),
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
@ -93,8 +93,8 @@ EXECUTE PROCEDURE updated_at_update();
|
||||||
CREATE TABLE IF NOT EXISTS solutions
|
CREATE TABLE IF NOT EXISTS solutions
|
||||||
(
|
(
|
||||||
id serial NOT NULL,
|
id serial NOT NULL,
|
||||||
task_id integer NOT NULL REFERENCES tasks (id),
|
task_id integer REFERENCES tasks (id) ON DELETE SET NULL,
|
||||||
participant_id integer NOT NULL REFERENCES participants (id),
|
participant_id integer REFERENCES participants (id) ON DELETE SET NULL,
|
||||||
solution varchar(1048576) NOT NULL,
|
solution varchar(1048576) NOT NULL,
|
||||||
state integer NOT NULL DEFAULT 1,
|
state integer NOT NULL DEFAULT 1,
|
||||||
score integer NOT NULL,
|
score integer NOT NULL,
|
||||||
|
|
Loading…
Add table
Reference in a new issue