[Store] Fix db migration

This commit is contained in:
Christian Pauly 2019-08-05 11:07:58 +02:00
parent 8e7c2a3f5b
commit 8c4e75d268

View file

@ -55,7 +55,7 @@ class Store {
_init() async { _init() async {
var databasePath = await getDatabasesPath(); var databasePath = await getDatabasesPath();
String path = p.join(databasePath, "FluffyMatrix.db"); String path = p.join(databasePath, "FluffyMatrix.db");
_db = await openDatabase(path, version: 8, _db = await openDatabase(path, version: 9,
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 {
@ -63,7 +63,7 @@ class Store {
print( print(
"[Store] Migrate databse from version $oldVersion to $newVersion"); "[Store] Migrate databse from version $oldVersion to $newVersion");
if (oldVersion != newVersion) { if (oldVersion != newVersion) {
await schemes.forEach((name, scheme) async { await schemes.forEach((String name, String scheme) async {
await db.execute("DROP TABLE IF EXISTS ?", [name]); await db.execute("DROP TABLE IF EXISTS ?", [name]);
}); });
db.rawUpdate("UPDATE Clients SET prev_batch='' WHERE client=?", db.rawUpdate("UPDATE Clients SET prev_batch='' WHERE client=?",
@ -97,7 +97,7 @@ class Store {
} }
Future<void> createTables(Database db) async { Future<void> createTables(Database db) async {
await schemes.forEach((name, scheme) async { await schemes.forEach((String name, String scheme) async {
await db.execute(scheme); await db.execute(scheme);
}); });
} }
@ -129,8 +129,8 @@ class Store {
Future<void> clear() async { Future<void> clear() async {
await _db await _db
.rawDelete("DELETE FROM Clients WHERE client=?", [client.clientName]); .rawDelete("DELETE FROM Clients WHERE client=?", [client.clientName]);
await schemes.forEach((name, scheme) async { await schemes.forEach((String name, String scheme) async {
if (name != "Clients") await db.rawDelete("DELETE FROM ?", [name]); if (name != "Clients") await db.rawDelete("DELETE FROM $name", [name]);
}); });
return; return;
} }