feat: merge auth&tester
This commit is contained in:
parent
0a2dea6c23
commit
441af4c6a2
72 changed files with 4910 additions and 2378 deletions
|
@ -15,18 +15,38 @@ $$
|
|||
DECLARE
|
||||
max_on_contest_tasks_amount integer := 50;
|
||||
BEGIN
|
||||
IF (
|
||||
SELECT count(*) FROM tasks
|
||||
WHERE contest_id = NEW.contest_id
|
||||
) >= (
|
||||
max_on_contest_tasks_amount
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Exceeded max tasks for this contest';
|
||||
END IF;
|
||||
IF (SELECT count(*)
|
||||
FROM tasks
|
||||
WHERE contest_id = NEW.contest_id) >= (
|
||||
max_on_contest_tasks_amount
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Exceeded max tasks for this contest';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users
|
||||
(
|
||||
id serial NOT NULL,
|
||||
username varchar(70) UNIQUE NOT NULL,
|
||||
hashed_pwd varchar(60) NOT NULL,
|
||||
role integer NOT NULL DEFAULT 0,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
|
||||
PRIMARY KEY (id),
|
||||
CHECK (length(username) != 0 AND username = lower(username) AND username = trim(username)),
|
||||
CHECK (length(hashed_pwd) != 0),
|
||||
CHECK (role BETWEEN 0 AND 2)
|
||||
);
|
||||
|
||||
CREATE TRIGGER on_users_update
|
||||
BEFORE UPDATE
|
||||
ON users
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE updated_at_update();
|
||||
|
||||
CREATE TABLE IF NOT EXISTS problems
|
||||
(
|
||||
id serial NOT NULL,
|
||||
|
@ -92,7 +112,8 @@ CREATE TABLE IF NOT EXISTS tasks
|
|||
);
|
||||
|
||||
CREATE TRIGGER max_tasks_on_contest_check
|
||||
BEFORE INSERT ON tasks
|
||||
BEFORE INSERT
|
||||
ON tasks
|
||||
FOR EACH STATEMENT
|
||||
EXECUTE FUNCTION check_max_tasks();
|
||||
|
||||
|
@ -105,8 +126,8 @@ 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),
|
||||
user_id integer NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||
contest_id integer NOT NULL REFERENCES contests (id) ON DELETE CASCADE,
|
||||
name varchar(64) NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
|
@ -121,7 +142,6 @@ CREATE TRIGGER on_participants_update
|
|||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE updated_at_update();
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS solutions
|
||||
(
|
||||
id serial NOT NULL,
|
||||
|
@ -144,7 +164,6 @@ CREATE TRIGGER on_solutions_update
|
|||
ON solutions
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE updated_at_update();
|
||||
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
|
@ -160,6 +179,8 @@ 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 FUNCTION IF EXISTS updated_at_update();
|
||||
DROP TRIGGER IF EXISTS on_users_update ON users;
|
||||
DROP TABLE IF EXISTS users;
|
||||
DROP FUNCTION IF EXISTS updated_at_update();
|
||||
DROP FUNCTION IF EXISTS check_max_tasks();
|
||||
-- +goose StatementEnd
|
Loading…
Add table
Add a link
Reference in a new issue