Skip to content

fix: persist toggled databases on the DATABASE_URL connection across reloads#17

Merged
matej21 merged 1 commit into
mainfrom
fix/server-managed-active-db-persistence
Jun 26, 2026
Merged

fix: persist toggled databases on the DATABASE_URL connection across reloads#17
matej21 merged 1 commit into
mainfrom
fix/server-managed-active-db-persistence

Conversation

@matej21

@matej21 matej21 commented Jun 26, 2026

Copy link
Copy Markdown
Member

Follow-up to #16.

Problem

After #16 stopped the Connection not found error 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_URL on 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 Set in backend-web/session.ts:

  • seed the connection config from it on session creation, so the existing fire-and-forget auto-connect reconnects those databases;
  • update it by wrapping the databases.activate / databases.deactivate handlers, mirroring the existing connections.list wrap.

Scope: this only affects the single shared DATABASE_URL connection (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) ✅
  • Browser against a real Postgres: activate a 2nd database → reload → still present; deactivate → reload → gone.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NxZYcCWNSKYkMqT3KYdwTB

…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
@matej21 matej21 merged commit 6dfc313 into main Jun 26, 2026
2 checks passed
@matej21 matej21 deleted the fix/server-managed-active-db-persistence branch June 26, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant