Basically rename and then update some values based on the row id where isNext = 1.
I suppose I need to use a Cursor as shown in this answer. So my code with auto-migration would look like this:
// For Auto-Migration
@RenameColumn(tableName = "Notifications", fromColumnName = "isNext", toColumnName = "wasShown")
static class MyAutoMigration implements AutoMigrationSpec {
@Override
public void onPostMigrate(@NonNull SupportSQLiteDatabase database) {
// Invoked once auto migration is done
Cursor cursor = database.query("SELECT * from Notifications WHERE wasShown = 1");
String row_id = String.valueOf(cursor.getPosition());
database.execSQL("UPDATE Notifications SET wasShown = 1 WHERE id < ?", new String[]{row_id});
database.execSQL("UPDATE Notifications SET wasShown = 0 WHERE id = ?", new String[]{row_id});
cursor.close();
}
}
Is it in some way "risky" to use such logic in migration code?
For example because it might throw exceptions, or something else happens that would crash the app.
I never worked with direct SQL manipulation through old-school cursors before, so I have the impression this logic might be fragile.


