Database changes
This commit is contained in:
parent
117a6950af
commit
f969d83d04
|
@ -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<void> createTables(Database db) async{
|
||||
await db.execute(ClientsScheme);
|
||||
await db.execute(RoomsScheme);
|
||||
await db.execute(ParticipantsScheme);
|
||||
await db.execute(EventsScheme);
|
||||
}
|
||||
|
||||
Future<String> queryPrevBatch() async{
|
||||
List<Map> list = await txn.rawQuery("SELECT prev_batch FROM Clients WHERE client=?", [client.clientName]);
|
||||
return list[0]["prev_batch"];
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue