mirror of
https://github.com/home-assistant/iOS.git
synced 2026-04-12 15:26:45 -05:00
27 lines
1.0 KiB
Swift
27 lines
1.0 KiB
Swift
import Foundation
|
|
import GRDB
|
|
|
|
final class CarPlayConfigTable: DatabaseTableProtocol {
|
|
var tableName: String { GRDBDatabaseTable.carPlayConfig.rawValue }
|
|
|
|
var definedColumns: [String] { DatabaseTables.CarPlayConfig.allCases.map(\.rawValue) }
|
|
|
|
func createIfNeeded(database: DatabaseQueue) throws {
|
|
let shouldCreateTable = try database.read { db in
|
|
try !db.tableExists(tableName)
|
|
}
|
|
if shouldCreateTable {
|
|
try database.write { db in
|
|
try db.create(table: tableName) { t in
|
|
t.primaryKey(DatabaseTables.CarPlayConfig.id.rawValue, .text).notNull()
|
|
t.column(DatabaseTables.CarPlayConfig.tabs.rawValue, .text).notNull()
|
|
t.column(DatabaseTables.CarPlayConfig.quickAccessItems.rawValue, .jsonText).notNull()
|
|
t.column(DatabaseTables.CarPlayConfig.quickAccessLayout.rawValue, .text)
|
|
}
|
|
}
|
|
} else {
|
|
try migrateColumns(database: database)
|
|
}
|
|
}
|
|
}
|