diff --git a/dal/db_query/queries.sql b/dal/db_query/queries.sql index 257d9ca..c060422 100644 --- a/dal/db_query/queries.sql +++ b/dal/db_query/queries.sql @@ -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; \ No newline at end of file diff --git a/dal/schema/000007_init.down.sql b/dal/schema/000007_init.down.sql new file mode 100644 index 0000000..374c55d --- /dev/null +++ b/dal/schema/000007_init.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE answer +DROP COLUMN start; \ No newline at end of file diff --git a/dal/schema/000007_init.up.sql b/dal/schema/000007_init.up.sql new file mode 100644 index 0000000..6b41425 --- /dev/null +++ b/dal/schema/000007_init.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE answer +ADD COLUMN start BOOLEAN NOT NULL DEFAULT FALSE; \ No newline at end of file diff --git a/sqlc.yaml b/sqlc.yaml index 31e8f53..625e6c4 100644 --- a/sqlc.yaml +++ b/sqlc.yaml @@ -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