diff --git a/lib/src/Store.dart b/lib/src/Store.dart index 8525a86..82bc77b 100644 --- a/lib/src/Store.dart +++ b/lib/src/Store.dart @@ -54,19 +54,16 @@ class Store { String path = p.join(databasePath, "FluffyMatrix.db"); _db = await openDatabase(path, version: 2, onCreate: (Database db, int version) async { - // When creating the db, create the table - await db.execute(ClientsScheme); - await db.execute(RoomsScheme); - await db.execute(ParticipantsScheme); - await db.execute(EventsScheme); + await createTables(db); }, onUpgrade: (Database db, int oldVersion, int newVersion) async{ if (oldVersion != newVersion) { - await db.rawDelete("DELETE FROM Rooms"); - await db.rawDelete("DELETE FROM Participants"); - await db.rawDelete("DELETE FROM Events"); + await db.execute("DROP TABLE IF EXISTS Rooms"); + await db.execute("DROP TABLE IF EXISTS Participants"); + await db.execute("DROP TABLE IF EXISTS Events"); db.rawUpdate("UPDATE Clients SET prev_batch='' WHERE client=?", [client.clientName]); + createTables(db); } }); @@ -89,6 +86,14 @@ class Store { client.connection.onLoginStateChanged.add(LoginState.loggedOut); } + + Future createTables(Database db) async{ + await db.execute(ClientsScheme); + await db.execute(RoomsScheme); + await db.execute(ParticipantsScheme); + await db.execute(EventsScheme); + } + Future queryPrevBatch() async{ List list = await txn.rawQuery("SELECT prev_batch FROM Clients WHERE client=?", [client.clientName]); return list[0]["prev_batch"]; diff --git a/test/ChatTime_test.dart b/test/ChatTime_test.dart index ff5888f..a1c9e5e 100644 --- a/test/ChatTime_test.dart +++ b/test/ChatTime_test.dart @@ -52,7 +52,7 @@ void main() { }); test("Formatting", () async { - final int timestamp = 1560144984758; + final int timestamp = DateTime.now().millisecondsSinceEpoch; final ChatTime chatTime = ChatTime(timestamp); //expect(chatTime.toTimeString(),"05:36"); // This depends on the time and your timezone ;) expect(chatTime.toTimeString(),chatTime.toEventTimeString());