-
Notifications
You must be signed in to change notification settings - Fork 141
Closed
Description
When configuring multiple SQLite databases in dbhub.toml, all source_id values query the same physical database (the last one configured).
Configuration
dbhub.toml:
[[sources]]
id = "database_a"
dsn = "sqlite:///app/database_a.db"
readonly = true
[[sources]]
id = "database_b"
dsn = "sqlite:///app/database_b.db"
readonly = truedocker-compose.yml:
services:
dbhub:
image: bytebase/dbhub:latest
working_dir: /app
ports:
- "8080:8080"
volumes:
- type: bind
source: ./database_a.db
target: /app/database_a.db
read_only: true
- type: bind
source: ./database_b.db
target: /app/database_b.db
read_only: true
- type: bind
source: ./dbhub.toml
target: /app/dbhub.toml
read_only: true
command:
- --transport
- http
- --port
- "8080"
- --config
- /app/dbhub.tomlExpected Behavior
source_id: "database_a"→ queries database_a.dbsource_id: "database_b"→ queries database_b.db
Actual Behavior
- Both source_ids query database_b.db (the last configured source)
- Only one database file is opened (confirmed via
lsof) - Both sources return identical tables despite files being different
Probably Cause
ConnectorRegistry.getConnectorForDSN() returns a singleton connector instance for SQLite:
static getConnectorForDSN(dsn) {
for (const connector of _ConnectorRegistry.connectors.values()) {
if (connector.dsnParser.isValidDSN(dsn)) {
return connector; // ← Same instance for all SQLite databases
}
}
}When connectSource() loops through sources, it:
- Gets the same SQLite connector instance for both databases
- Calls
connector.connect(actualDSN)which overwrites the previous connection - Stores the same connector instance for both source_ids
Result: Both source_ids reference the same connector connected to only the last database.
Probable Fix
ConnectorRegistry should create a new connector instance per source, not return a singleton.
Metadata
Metadata
Assignees
Labels
No labels