update new queries with new bool var start

This commit is contained in:
Pavel 2024-03-15 14:27:08 +03:00
parent 0adfe44ab8
commit aadccd6571
4 changed files with 13 additions and 7 deletions

@ -282,8 +282,7 @@ WHERE privilege_name = $2
AND (amount < $3 OR created_at <= NOW() - INTERVAL '1 month');
-- name: GetAllAnswersByQuizID :many
SELECT DISTINCT ON(question_id) content, created_at, question_id, id FROM answer WHERE session = $1 ORDER BY question_id ASC, created_at DESC;
SELECT DISTINCT ON(question_id) content, created_at, question_id, id FROM answer WHERE session = $1 AND start = false ORDER BY question_id ASC, created_at DESC;
-- name: InsertAnswers :exec
INSERT INTO answer(
content,
@ -297,12 +296,13 @@ INSERT INTO answer(
device,
os,
browser,
ip
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);
ip,
start
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13);
-- name: GetResultAnswers :many
SELECT DISTINCT on (question_id) id, content, quiz_id, question_id, fingerprint, session,created_at, result, new,deleted FROM answer WHERE session = (
SELECT session FROM answer WHERE answer.id = $1) ORDER BY question_id, created_at DESC;
SELECT session FROM answer WHERE answer.id = $1) AND start = false ORDER BY question_id, created_at DESC;
-- name: GetQuestions :many
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE quiz_id = $1 AND deleted = FALSE;
@ -314,7 +314,7 @@ UPDATE answer SET deleted = TRUE WHERE id = $1 AND deleted = FALSE;
SELECT a.id
FROM answer a
JOIN quiz q ON a.quiz_id = q.id
WHERE a.id = ANY($1::bigint[]) AND a.deleted = FALSE AND q.accountid = $2;
WHERE a.id = ANY($1::bigint[]) AND a.deleted = FALSE AND q.accountid = $2 AND a.start = false;
-- name: CheckResultOwner :one
SELECT q.accountid FROM answer a JOIN quiz q ON a.quiz_id = q.id WHERE a.id = $1 AND a.deleted = FALSE;
SELECT q.accountid FROM answer a JOIN quiz q ON a.quiz_id = q.id WHERE a.id = $1 AND a.deleted = FALSE AND a.start = false;

@ -0,0 +1,2 @@
ALTER TABLE answer
DROP COLUMN start;

@ -0,0 +1,2 @@
ALTER TABLE answer
ADD COLUMN start BOOLEAN NOT NULL DEFAULT FALSE;

@ -16,6 +16,8 @@ packages:
- "./dal/schema/000005_init.down.sql"
- "./dal/schema/000006_init.up.sql"
- "./dal/schema/000006_init.down.sql"
- "./dal/schema/000007_init.up.sql"
- "./dal/schema/000007_init.down.sql"
engine: "postgresql"
emit_json_tags: true
emit_db_tags: true