-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from codex-team/285-fix-join-route-user-dupli…
…cation fix: adds unique index on note and user id of teams table
- Loading branch information
Showing
3 changed files
with
26 additions
and
6 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
migrations/tenant/0035-note-teams@add-unique-index-on-note-and-user-id.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- remove exists duplicate entries from database | ||
DELETE FROM note_teams | ||
WHERE id IN ( | ||
SELECT id | ||
FROM ( | ||
SELECT | ||
id, | ||
ROW_NUMBER() OVER ( | ||
PARTITION BY note_id, user_id | ||
ORDER BY id | ||
) AS row_num | ||
FROM note_teams | ||
) AS duplicates | ||
WHERE duplicates.row_num > 1 | ||
); | ||
|
||
-- adds unique index | ||
CREATE UNIQUE INDEX IF NOT EXISTS note_teams_note_id_user_id_unique_idx | ||
ON public.note_teams (note_id, user_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters