fix: persist toggled databases on the DATABASE_URL connection across reloads#17
Merged
Merged
Conversation
…reloads After #16 removed the error when toggling extra databases on a server-managed (DATABASE_URL) connection, the toggle worked in-session but the databases vanished on page reload: each WebSocket gets a fresh in-memory app DB and the env connection is recreated from DATABASE_URL with no memory of what was activated. Remember the env connection's active databases in a process-scoped set, seed the connection config from it on session creation (so the fire-and-forget auto-connect reconnects them), and update it by wrapping the databases.activate/deactivate handlers — mirroring the existing connections.list wrap. Verified in a browser against a real Postgres: activate a second database, reload → it is still present; deactivate, reload → it is gone. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NxZYcCWNSKYkMqT3KYdwTB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #16.
Problem
After #16 stopped the
Connection not founderror when toggling extra databases on a server-managed (DATABASE_URL) connection, the toggle worked in-session but the activated databases disappeared on page reload.Each WebSocket gets a fresh in-memory app DB, and the env connection is recreated from
DATABASE_URLon every session with no memory of what was activated — so nothing durable held the active-database list.Fix
Remember the env connection's active databases in a process-scoped
Setinbackend-web/session.ts:databases.activate/databases.deactivatehandlers, mirroring the existingconnections.listwrap.Scope: this only affects the single shared
DATABASE_URLconnection (web mode). It is process-scoped — shared across sessions of that one connection and reset on server restart (the env connection is ephemeral by nature).Verification
bun run typecheck✅,biome lint✅,bun test(web-session / ephemeral-session / env-connection: 45 pass) ✅🤖 Generated with Claude Code
https://claude.ai/code/session_01NxZYcCWNSKYkMqT3KYdwTB