Browse files

Fix grouping sources by component_name during migration

Ensure that if multiple rows have the same component_name, the selected state is set to the maximum of all available states, avoiding cases where the DISTINCT would still give more than one row for a given component_name.
  • Loading branch information...
ianhanniballake committed Nov 9, 2017
1 parent 0904203 commit 2a04d87d5f82eb0a60c66e1092ecf3d67577d46b
@@ -134,9 +134,9 @@ public void migrate(@NonNull final SupportSQLiteDatabase database) {
// Just move over the component_name and selected flag then
database.execSQL("INSERT INTO sources2 " +
"(component_name, selected, network, supports_next_artwork, commands) "
+ "SELECT DISTINCT component_name, selected, "
+ "SELECT component_name, MAX(selected), "
+ "0 AS network, 0 AS supports_next_artwork, '' as commands "
+ "FROM sources");
+ "FROM sources GROUP BY component_name");
database.execSQL("DROP TABLE sources");
database.execSQL("ALTER TABLE sources2 RENAME TO sources");

0 comments on commit 2a04d87

Please sign in to comment.