Merge branch 'store-fix-db-migration' into 'master'

[Store] fix db migration

See merge request famedly/famedlysdk!51
This commit is contained in:
Marcel 2019-07-26 10:34:12 +00:00
commit 670110e661

View file

@ -59,7 +59,9 @@ class Store {
onCreate: (Database db, int version) async { onCreate: (Database db, int version) async {
await createTables(db); await createTables(db);
}, onUpgrade: (Database db, int oldVersion, int newVersion) async { }, onUpgrade: (Database db, int oldVersion, int newVersion) async {
print("Migrate databse from version $oldVersion to $newVersion"); if (client.debug)
print(
"[Store] Migrate databse from version $oldVersion to $newVersion");
if (oldVersion != newVersion) { if (oldVersion != newVersion) {
await db.execute("DROP TABLE IF EXISTS Rooms"); await db.execute("DROP TABLE IF EXISTS Rooms");
await db.execute("DROP TABLE IF EXISTS Participants"); await db.execute("DROP TABLE IF EXISTS Participants");
@ -68,7 +70,7 @@ class Store {
await db.execute("DROP TABLE IF EXISTS NotificationsCache"); await db.execute("DROP TABLE IF EXISTS NotificationsCache");
db.rawUpdate("UPDATE Clients SET prev_batch='' WHERE client=?", db.rawUpdate("UPDATE Clients SET prev_batch='' WHERE client=?",
[client.clientName]); [client.clientName]);
createTables(db); await createTables(db);
} }
}); });
@ -90,7 +92,8 @@ class Store {
? null ? null
: clientList["prev_batch"], : clientList["prev_batch"],
); );
print("Restore client credentials of ${client.userID}"); if (client.debug)
print("[Store] Restore client credentials of ${client.userID}");
} else } else
client.connection.onLoginStateChanged.add(LoginState.loggedOut); client.connection.onLoginStateChanged.add(LoginState.loggedOut);
} }