[Database/Librus] Fix duplicate homework

This commit is contained in:
Kacper Ziubryniewicz 2019-10-13 17:00:54 +02:00
parent 70d35e12e5
commit 6ff439b20d
2 changed files with 10 additions and 3 deletions

View File

@ -2821,7 +2821,7 @@ public class Librus implements EdziennikInterface {
); );
eventList.add(eventObject); eventList.add(eventObject);
metadataList.add(new Metadata(profileId, Metadata.TYPE_EVENT, eventObject.id, profile.getEmpty(), profile.getEmpty(), addedDate.getInMillis())); metadataList.add(new Metadata(profileId, Metadata.TYPE_HOMEWORK, eventObject.id, profile.getEmpty(), profile.getEmpty(), addedDate.getInMillis()));
} }
r("finish", "Homework"); r("finish", "Homework");
} }

View File

@ -87,7 +87,7 @@ import android.content.Context;
DebugLog.class, DebugLog.class,
EndpointTimer.class, EndpointTimer.class,
LessonRange.class, LessonRange.class,
Metadata.class}, version = 57) Metadata.class}, version = 58)
@TypeConverters({ @TypeConverters({
ConverterTime.class, ConverterTime.class,
ConverterDate.class, ConverterDate.class,
@ -597,6 +597,12 @@ public abstract class AppDb extends RoomDatabase {
database.execSQL("ALTER TABLE gradeCategories ADD type INTEGER NOT NULL DEFAULT 0"); database.execSQL("ALTER TABLE gradeCategories ADD type INTEGER NOT NULL DEFAULT 0");
} }
}; };
private static final Migration MIGRATION_57_58 = new Migration(57, 58) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("UPDATE metadata SET thingType = 5 WHERE thingType = 4 AND thingId IN (SELECT eventId FROM events WHERE eventType = -1)");
}
};
public static AppDb getDatabase(final Context context) { public static AppDb getDatabase(final Context context) {
@ -651,7 +657,8 @@ public abstract class AppDb extends RoomDatabase {
MIGRATION_53_54, MIGRATION_53_54,
MIGRATION_54_55, MIGRATION_54_55,
MIGRATION_55_56, MIGRATION_55_56,
MIGRATION_56_57 MIGRATION_56_57,
MIGRATION_57_58
) )
.allowMainThreadQueries() .allowMainThreadQueries()
//.fallbackToDestructiveMigration() //.fallbackToDestructiveMigration()