Skip to content

Commit 88ba042

Browse files
committed
refactor: self-describing plugin system — zero core changes for new drivers
1 parent ea306b2 commit 88ba042

41 files changed

Lines changed: 409 additions & 580 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

TablePro/AppDelegate+ConnectionHandler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ extension AppDelegate {
141141
let connectionName = url.deletingPathExtension().lastPathComponent
142142

143143
for (sessionId, session) in DatabaseManager.shared.activeSessions {
144-
if session.connection.type == .duckdb
144+
if session.connection.type == DatabaseType(rawValue: "DuckDB")
145145
&& session.connection.database == filePath
146146
&& session.driver != nil {
147147
bringConnectionWindowToFront(sessionId)
@@ -155,7 +155,7 @@ extension AppDelegate {
155155
port: 0,
156156
database: filePath,
157157
username: "",
158-
type: .duckdb
158+
type: DatabaseType(rawValue: "DuckDB")
159159
)
160160

161161
openNewConnectionWindow(for: connection)

TablePro/AppDelegate+FileOpen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extension AppDelegate {
6666
switch dbType {
6767
case .sqlite:
6868
self.handleSQLiteFile(url)
69-
case .duckdb:
69+
case DatabaseType(rawValue: "DuckDB"):
7070
self.handleDuckDBFile(url)
7171
default:
7272
self.handleGenericDatabaseFile(url, type: dbType)

TablePro/Core/Database/DatabaseDriver.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,15 @@ enum DatabaseDriverFactory {
362362
}
363363

364364
switch connection.type {
365-
case .mongodb:
365+
case DatabaseType(rawValue: "MongoDB"):
366366
fields["sslCACertPath"] = ssl.caCertificatePath
367367
fields["mongoReadPreference"] = connection.mongoReadPreference ?? ""
368368
fields["mongoWriteConcern"] = connection.mongoWriteConcern ?? ""
369-
case .redis:
369+
case DatabaseType(rawValue: "Redis"):
370370
fields["redisDatabase"] = String(connection.redisDatabase ?? 0)
371-
case .mssql:
371+
case DatabaseType(rawValue: "SQL Server"):
372372
fields["mssqlSchema"] = connection.mssqlSchema ?? "dbo"
373-
case .oracle:
373+
case DatabaseType(rawValue: "Oracle"):
374374
fields["oracleServiceName"] = connection.oracleServiceName ?? ""
375375
default:
376376
break

TablePro/Core/Database/DatabaseManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ final class DatabaseManager {
803803
driver: DatabaseDriver
804804
) async -> String? {
805805
// Only needed for PostgreSQL PK modifications
806-
guard databaseType == .postgresql || databaseType == .redshift || databaseType == .duckdb else { return nil }
806+
guard databaseType == .postgresql || databaseType == .redshift || databaseType == DatabaseType(rawValue: "DuckDB") else { return nil }
807807
guard
808808
changes.contains(where: {
809809
if case .modifyPrimaryKey = $0 { return true }

TablePro/Core/Plugins/PluginManager.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,27 @@ final class PluginManager {
251251
Self.logger.error("Plugin '\(pluginId)' driver rejected: \(error.localizedDescription)")
252252
}
253253
if !driverPlugins.keys.contains(type(of: driver).databaseTypeId) {
254-
let typeId = type(of: driver).databaseTypeId
254+
let driverType = type(of: driver)
255+
let typeId = driverType.databaseTypeId
255256
driverPlugins[typeId] = driver
256-
for additionalId in type(of: driver).additionalDatabaseTypeIds {
257+
for additionalId in driverType.additionalDatabaseTypeIds {
257258
driverPlugins[additionalId] = driver
258259
}
259260

260-
// Built-in defaults are pre-populated in PluginMetadataRegistry.init().
261-
// Runtime-loaded plugins may be compiled against an older TableProPluginKit,
262-
// so we don't read new protocol properties from them to avoid witness table crashes.
261+
// Self-register plugin metadata from the DriverPlugin protocol
262+
let driverInstance = driver.createDriver(config: DriverConnectionConfig(
263+
host: "", port: 0, username: "", password: "", database: ""
264+
))
265+
let snapshot = PluginMetadataRegistry.shared.buildMetadataSnapshot(
266+
from: driverType,
267+
isDownloadable: driverType.isDownloadable,
268+
parameterStyle: driverInstance.parameterStyle
269+
)
270+
PluginMetadataRegistry.shared.register(snapshot: snapshot, forTypeId: typeId)
271+
for additionalId in driverType.additionalDatabaseTypeIds {
272+
PluginMetadataRegistry.shared.register(snapshot: snapshot, forTypeId: additionalId)
273+
PluginMetadataRegistry.shared.registerTypeAlias(additionalId, primaryTypeId: typeId)
274+
}
263275

264276
Self.logger.debug("Registered driver plugin '\(pluginId)' for database type '\(typeId)'")
265277
registeredAny = true

0 commit comments

Comments
 (0)