From 5fa7c068df9bcbc287b1580db5e690033d28617a Mon Sep 17 00:00:00 2001 From: Bhattarapong Somwong Date: Wed, 5 Jun 2024 11:47:53 +0700 Subject: [PATCH 1/2] #623 add unique constraint to detection_reviews table --- ...d-unique-constraint-to-detection-reviews.js | 18 ++++++++++++++++++ core/detections/review.int.test.js | 10 +++++----- 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 core/_cli/migrations/20240604172307-add-unique-constraint-to-detection-reviews.js diff --git a/core/_cli/migrations/20240604172307-add-unique-constraint-to-detection-reviews.js b/core/_cli/migrations/20240604172307-add-unique-constraint-to-detection-reviews.js new file mode 100644 index 000000000..24a0b62fb --- /dev/null +++ b/core/_cli/migrations/20240604172307-add-unique-constraint-to-detection-reviews.js @@ -0,0 +1,18 @@ +'use strict' + +module.exports = { + up: async (queryInterface) => { + await queryInterface.sequelize.query(` + ALTER TABLE + "public"."detection_reviews" + ADD CONSTRAINT detection_reviews_unique_detection_id_user_id_constraint UNIQUE (detection_id, user_id) + `) + }, + down: async (queryInterface) => { + await queryInterface.sequelize.query(` + ALTER TABLE + "public"."detection_reviews" + DROP CONSTRAINT detection_reviews_unique_detection_id_user_id_constraint IF EXISTS + `) + } +} diff --git a/core/detections/review.int.test.js b/core/detections/review.int.test.js index ba2c525e0..eefc4948a 100644 --- a/core/detections/review.int.test.js +++ b/core/detections/review.int.test.js @@ -2844,12 +2844,12 @@ describe('POST /:streamId/detections/:start/review', () => { }) await DetectionReview.create({ detectionId: detection.toJSON().id, - userId: seedValues.otherUserId, + userId: seedValues.anotherUserId, status: -1 }) await DetectionReview.create({ detectionId: detection.toJSON().id, - userId: seedValues.otherUserId, + userId: seedValues.differentUserId, status: -1 }) @@ -2885,17 +2885,17 @@ describe('POST /:streamId/detections/:start/review', () => { }) await DetectionReview.create({ detectionId: detection.toJSON().id, - userId: seedValues.otherUserId, + userId: seedValues.anotherUserId, status: 1 }) await DetectionReview.create({ detectionId: detection.toJSON().id, - userId: seedValues.primaryUserId, + userId: seedValues.differentUserId, status: -1 }) await DetectionReview.create({ detectionId: detection.toJSON().id, - userId: seedValues.otherUserId, + userId: seedValues.primaryUserId, status: -1 }) From 6f08593e0ef49abbb11a24969a5abd3071284276 Mon Sep 17 00:00:00 2001 From: Bhattarapong Somwong Date: Wed, 5 Jun 2024 18:41:50 +0700 Subject: [PATCH 2/2] #623 update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c5883c62..9c0572461 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 1.3.12 (2024-06-xx) ### Features * **core**: Endpoint `POST /streams/:streamId/detections/:start/review` now returns the review status and id of the detection that has been reviewed in the call. +* **core**: Create unique constraint of `(detection_id, user_id)` inside `detection_reviews` table. ### Common * **core**: Remove `jwt-custom` and merge custom into list