2024-08-11 00:28:01 +00:00
|
|
|
import Foundation
|
|
|
|
import GRDB
|
|
|
|
|
|
|
|
extension Database {
|
|
|
|
static var migrator: DatabaseMigrator = {
|
|
|
|
var migrator = DatabaseMigrator()
|
|
|
|
|
|
|
|
// flush db on schema change (only in DEV mode)
|
|
|
|
#if DEBUG
|
|
|
|
migrator.eraseDatabaseOnSchemaChange = true
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// 1st migration - basic tables
|
|
|
|
migrator.registerMigration("Add basic tables") { db in
|
|
|
|
// credentials
|
|
|
|
try db.create(table: "credentials", options: [.ifNotExists]) { table in
|
|
|
|
table.column("bareJid", .text).notNull().primaryKey().unique(onConflict: .replace)
|
|
|
|
table.column("pass", .text).notNull()
|
|
|
|
table.column("isActive", .boolean).notNull().defaults(to: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// rosters
|
|
|
|
try db.create(table: "rosterVersions", options: [.ifNotExists]) { table in
|
|
|
|
table.column("bareJid", .text).notNull().primaryKey().unique(onConflict: .replace)
|
|
|
|
table.column("version", .text).notNull()
|
|
|
|
}
|
|
|
|
try db.create(table: "rosters", options: [.ifNotExists]) { table in
|
|
|
|
table.column("bareJid", .text).notNull()
|
|
|
|
table.column("contactBareJid", .text).notNull()
|
|
|
|
table.column("name", .text)
|
|
|
|
table.column("subscription", .text).notNull()
|
|
|
|
table.column("ask", .boolean).notNull().defaults(to: false)
|
|
|
|
table.column("data", .text).notNull()
|
|
|
|
table.primaryKey(["bareJid", "contactBareJid"], onConflict: .replace)
|
|
|
|
table.column("locallyDeleted", .boolean).notNull().defaults(to: false)
|
|
|
|
}
|
2024-08-11 23:52:45 +00:00
|
|
|
|
|
|
|
// chats
|
|
|
|
try db.create(table: "chats", options: [.ifNotExists]) { table in
|
|
|
|
table.column("id", .text).notNull().primaryKey().unique(onConflict: .replace)
|
|
|
|
table.column("account", .text).notNull()
|
|
|
|
table.column("participant", .text).notNull()
|
|
|
|
table.column("type", .integer).notNull()
|
|
|
|
}
|
2024-08-11 00:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return migrator
|
|
|
|
return migrator
|
|
|
|
}()
|
|
|
|
}
|