Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Make sure that related shows are unique #1902

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ CREATE INDEX IF NOT EXISTS `index_related_shows_show_id` ON `related_shows` (`sh

CREATE INDEX IF NOT EXISTS `index_related_shows_other_show_id` ON `related_shows` (`other_show_id`);

CREATE UNIQUE INDEX IF NOT EXISTS `index_related_shows_unique` ON `related_shows` (`show_id`, `other_show_id`);

-- queries

entries:
Expand Down
10 changes: 10 additions & 0 deletions data/db-sqldelight/src/commonMain/sqldelight/migrations/33.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

-- delete duplicate related shows
DELETE FROM `related_shows` WHERE rowid NOT IN (
SELECT MIN(rowid)
FROM related_shows
GROUP BY show_id, other_show_id
);

-- finally add an index to make sure this doesn't happen in the future
CREATE UNIQUE INDEX IF NOT EXISTS `index_related_shows_unique` ON `related_shows` (`show_id`, `other_show_id`);
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class RelatedShowsStore(
showId = showId,
otherShowId = showDao.getIdOrSavePlaceholder(show),
)
}
}.distinctBy { it.otherShowId }
}
}
}
Expand Down
Loading