-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
61 additions
and
16 deletions.
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
src/migrator/migrations/014_file_subtitle_infohash_fileidx_index.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,43 @@ | ||
-- Drop Duplicate Files in Files Table | ||
DELETE FROM public.files | ||
WHERE id NOT IN ( | ||
SELECT MAX(id) | ||
FROM public.files | ||
GROUP BY "infoHash", "fileIndex" | ||
); | ||
|
||
-- Add Index to files table | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 | ||
FROM pg_constraint | ||
WHERE conname = 'files_unique_infohash_fileindex' | ||
) THEN | ||
ALTER TABLE public.files | ||
ADD CONSTRAINT files_unique_infohash_fileindex UNIQUE ("infoHash", "fileIndex"); | ||
END IF; | ||
END $$; | ||
|
||
|
||
-- Drop Duplicate subtitles in Subtitles Table | ||
DELETE FROM public.subtitles | ||
WHERE id NOT IN ( | ||
SELECT MAX(id) | ||
FROM public.subtitles | ||
GROUP BY "infoHash", "fileIndex" | ||
); | ||
|
||
-- Add Index to subtitles table | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 | ||
FROM pg_constraint | ||
WHERE conname = 'subtitles_unique_infohash_fileindex' | ||
) THEN | ||
ALTER TABLE public.subtitles | ||
ADD CONSTRAINT subtitles_unique_infohash_fileindex UNIQUE ("infoHash", "fileIndex"); | ||
END IF; | ||
END $$; | ||
|
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