Repository navigation
fix(cli): let a second database on the same server join a runtime's integrated storage - #2623
Conversation
…ntegrated storage - A second application database on the server that already holds a runtime's integrated storage joins that runtime. Its own connection reference names the same schemabot database, so registration now accepts it when the server address and database match exactly. The runtime keeps the storage reference it was set up with. - A registration whose state database is elsewhere is refused with where the runtime keeps its state and the flags for each way forward: add the database to that runtime, or give it a runtime and profile of its own. - When integrated setup finds a schemabot database that another local runtime already keeps its state in, the refusal names that runtime and the --runtime flag that adds this database to it. - A connection read from an unset environment variable is refused naming the variable, rather than as a connection that names no database. - docs/cli.md and docs/init.md describe joining, and AZ-7's enforcement line names the new file.
There was a problem hiding this comment.
🟡 Changes recommended
Connection validation can accept off-server registrations through differing fallback endpoints and reject valid resolver-provided connections, compromising isolation and blocking integrated joins.
2 open issues
What changed in this PR
Allows another application database on the same server to join a local SchemaBot runtime’s integrated storage while retaining its existing storage reference. This extends the registration guard associated with AZ-7.
Changes:
- Compare resolved storage addresses when integrated connection references differ.
- Add actionable storage-conflict and unset-variable errors.
- Cover joining with unit and integration tests, and document the workflow.
For two application databases using different connection variables on the same server:
Before: second init -> different references -> registration refused
After: second init -> same storage address -> joins existing runtime
Unset connection variable: before
Error: database "prisma_app" environment "development": DSN must name a database
Unset connection variable: after
Error: database "prisma_app" environment "development": environment variable PRISMA_DSN is not set
Upgrade notes: None.
| File | Description |
|---|---|
pkg/localsetup/register.go |
Allows matching integrated storage to join. |
pkg/localsetup/register_test.go |
Covers joining, refusals, and runtime lookup. |
pkg/localsetup/integrated_storage.go |
Names the runtime using existing state. |
pkg/localsetup/integrated_storage_test.go |
Checks storage-creation guidance. |
pkg/localsetup/integrated_join.go |
Adds address comparison and runtime discovery. |
pkg/localsetup/check_connection_test.go |
Updates the error-helper call. |
pkg/cmd/commands/init.go |
Adds storage-conflict remedies. |
pkg/cmd/commands/init_test.go |
Checks actionable error wording. |
pkg/api/storage_isolation.go |
Detects unset connection variables. |
pkg/api/storage_isolation_test.go |
Covers missing-variable diagnostics. |
integration/localruntime/init_second_database_test.go |
Exercises joining on MySQL and PostgreSQL. |
docs/invariants.md |
Updates AZ-7’s enforcement references. |
docs/init.md |
Explains integrated runtime joining. |
docs/cli.md |
Documents connection and runtime requirements. |
Review effort: Balanced
…oining storage - Two PostgreSQL integrated storages join only when every endpoint their connections may reach matches, fallback hosts included. A connection that shares the first host but falls back to another server is a different state database and is refused. - Connection references are resolved through the registered secret resolvers, the way the runtime resolves them, before an unset env: variable is reported. A resolver registered for the env prefix keeps its precedence over the process environment.
|
🤖 I reviewed the full diff at Blocker — At
This was a local static review. I couldn't retrieve a Builderbot result for this head, and I did not run tests. |
…al servers - A PostgreSQL storage connection that lists more than one host reaches whichever answers first, so two such connections cannot be shown to share a state database, whatever order or hosts they list. A registration whose integrated storage names more than one server no longer joins; it is refused as storage that differs. Fallbacks that differ only in TLS settings name one server and still join. - The storage connection is resolved once for both the unset-variable check and the database-name rewrite, so the value checked is the value parsed and a remote resolver is asked once. ResolveStorageDSN returns both.
|
🤖 Thanks, both points are fixed in 454c53a.
— Claude Code (Claude Opus 5.5) |


Why
Most developers run one local database server with a database per application. After
init --integratedsets up the first application, a second one on the same server cannot be added, and none of the errors names a way through:schemabotdatabase through each application's own connection variable. The second application names the same state database through a different variable, so registration refuses it as "runtime storage differs; registration cannot replace durable state storage".schemabotdatabase already exists, with advice to "choose standalone", a wizard choice that names no flag.What
schemabotdatabase already holds another local runtime's state, init names that runtime and the--runtimeflag that adds this database to it.docs/cli.mdanddocs/init.mddescribe joining.Before and after
prisma_appwas set up withinit --integrated --dsn env:PRISMA_DSN.drizzle_appis on the same server, at the same host and port.State database on another server: before and after
Before:
After:
A new runtime on a server whose schemabot database another runtime uses: before and after
Before:
After:
An unset connection variable: before and after
Before:
After:
How
Registration still compares storage configuration first. Only when the configurations differ, and both are integrated storage, does it resolve both connections and compare the server address and database. A host alias or a tunnel may reach the same server under another name. That case is refused with the remedy rather than joined, since joining the wrong server would split an application's history across two state databases.
Risk
The change affects only local runtimes set up by
init. Joining needs an exact address match, so the worst outcome of a mismatch is a refusal with a remedy.pkg/localsetup/integrated_join.go, where the join decision lives.Upgrade notes
None.
🤖 Generated with Claude Code