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

Commit

Permalink
Make sure that related shows are unique (#1902)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbanes authored Jun 24, 2024
1 parent 13163fa commit ca540a8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
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

0 comments on commit ca540a8

Please sign in to comment.