Files
iOS/Sources/Shared/Database/Tables/CarPlayConfigTable.swift
2026-03-30 22:42:09 +02:00

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)
}
}
}