Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit a6f12cf

Browse files
author
Thomas Horta
committed
Remove Migration and fallback to destructive migration
Since UPSERT is not supported by all Android API versions and the actual data inside the Prompts table changed along with the schema, it will be best to avoid the effort of maintaing stale data and just rely on Room's fallback to destructive migration, which will drop the table (and data) and create a new one with the correct schema. This shouldn't have many downsides as we fetch new data as soon as the app opens and the user reaches the Dashboard. The only possible caveat is for users that have reminders setup with Prompts enabled, that might see a notification without Blogging Prompts if they don't open the app after updating it.
1 parent 04da183 commit a6f12cf

File tree

1 file changed

+0
-38
lines changed

1 file changed

+0
-38
lines changed

fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WPAndroidDatabase.kt

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ abstract class WPAndroidDatabase : RoomDatabase() {
105105
.addMigrations(MIGRATION_18_19)
106106
.addMigrations(MIGRATION_19_20)
107107
.addMigrations(MIGRATION_20_21)
108-
.addMigrations(MIGRATION_21_22)
109108
.build()
110109

111110
val MIGRATION_1_2 = object : Migration(1, 2) {
@@ -311,42 +310,5 @@ abstract class WPAndroidDatabase : RoomDatabase() {
311310
}
312311
}
313312
}
314-
315-
val MIGRATION_21_22 = object : Migration(21, 22) {
316-
override fun migrate(database: SupportSQLiteDatabase) {
317-
// migrate old data to new table schema
318-
database.apply {
319-
execSQL(
320-
"CREATE TABLE IF NOT EXISTS `BloggingPrompts_new` (" +
321-
"`id` INTEGER NOT NULL," +
322-
"`siteLocalId` INTEGER NOT NULL," +
323-
"`text` TEXT NOT NULL," +
324-
"`date` TEXT NOT NULL," +
325-
"`isAnswered` INTEGER NOT NULL," +
326-
"`respondentsCount` INTEGER NOT NULL," +
327-
"`attribution` TEXT NOT NULL," +
328-
"`respondentsAvatars` TEXT NOT NULL," +
329-
"`answeredLink` TEXT NOT NULL," +
330-
"PRIMARY KEY(`date`)" +
331-
")"
332-
)
333-
334-
val tagPrefix = "https://wordpress.com/tag/dailyprompt-"
335-
execSQL(
336-
"INSERT INTO BloggingPrompts_new (" +
337-
"id, siteLocalId, text, date, isAnswered, " +
338-
"respondentsCount, attribution, respondentsAvatars, answeredLink) " +
339-
"SELECT id, siteLocalId, text, date, isAnswered, " +
340-
"respondentsCount, attribution, respondentsAvatars, " +
341-
"'$tagPrefix' || id FROM BloggingPrompts " +
342-
"WHERE true " +
343-
"ON CONFLICT DO NOTHING"
344-
)
345-
346-
execSQL("DROP TABLE `BloggingPrompts`")
347-
execSQL("ALTER TABLE `BloggingPrompts_new` RENAME TO `BloggingPrompts`")
348-
}
349-
}
350-
}
351313
}
352314
}

0 commit comments

Comments
 (0)