wip
This commit is contained in:
parent
bb76ac49a1
commit
339aab2bb4
|
@ -94,13 +94,21 @@ extension Database {
|
||||||
table.primaryKey(["account", "id"], onConflict: .replace)
|
table.primaryKey(["account", "id"], onConflict: .replace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
try db.alter(table: "messages") { table in
|
try db.alter(table: "messages") { table in
|
||||||
table.add(column: "secure", .boolean).notNull().defaults(to: false)
|
table.add(column: "secure", .boolean).notNull().defaults(to: false)
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
print("Error adding columns: \(error)\nProbably already added")
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
try db.alter(table: "chats") { table in
|
try db.alter(table: "chats") { table in
|
||||||
table.add(column: "encrypted", .boolean).notNull().defaults(to: false)
|
table.add(column: "encrypted", .boolean).notNull().defaults(to: false)
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
print("Error adding columns: \(error)\nProbably already added")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return migrator
|
// return migrator
|
||||||
|
|
|
@ -60,11 +60,20 @@ private extension Database {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
extension Database {
|
extension Database {
|
||||||
func flushAllData() {
|
func flushAllData() {
|
||||||
// nullable queue and remove db file
|
|
||||||
do {
|
do {
|
||||||
try FileManager.default.removeItem(atPath: dbPath)
|
try dbQueue.write { db in
|
||||||
|
// Fetch all table names
|
||||||
|
let tables = try String.fetchAll(db, sql: """
|
||||||
|
SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';
|
||||||
|
""")
|
||||||
|
|
||||||
|
// Generate and execute DELETE statements for each table
|
||||||
|
for table in tables {
|
||||||
|
try db.execute(sql: "DELETE FROM \(table);")
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
print("Error: \(error)")
|
print("Error flushing all data: \(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,7 +202,6 @@ private extension ClientsStore {
|
||||||
clients.removeAll()
|
clients.removeAll()
|
||||||
actualRosters.removeAll()
|
actualRosters.removeAll()
|
||||||
actualChats.removeAll()
|
actualChats.removeAll()
|
||||||
ready = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -33,4 +33,9 @@ enum UserSettings {
|
||||||
|
|
||||||
@Storage(key: kSecureChatsByDefault, defaultValue: false)
|
@Storage(key: kSecureChatsByDefault, defaultValue: false)
|
||||||
static var secureChatsByDefault: Bool
|
static var secureChatsByDefault: Bool
|
||||||
|
|
||||||
|
static func reset() {
|
||||||
|
omemoDeviceId = 0
|
||||||
|
secureChatsByDefault = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,7 @@ struct SettingsScreen: View {
|
||||||
Button("Delete", role: .destructive) {
|
Button("Delete", role: .destructive) {
|
||||||
clientsStore.flushAllData()
|
clientsStore.flushAllData()
|
||||||
Database.shared.flushAllData()
|
Database.shared.flushAllData()
|
||||||
|
UserSettings.reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue