Repository navigation
feat(runtime): share local Postgres through a server dependency - #194
Closed
antoinetoussaint-byte wants to merge 1 commit into
Closed
antoinetoussaint-byte wants to merge 1 commit into
antoinetoussaint-byte wants to merge 1 commit into
Conversation
This was referenced Oct 27, 2026
Contributor
Author
|
Superseded by #196 (a218ae5, merged): one shared native Postgres server per run with a database and a non-superuser owner per service, needing no composition declaration. #194 required every composition to declare a dependency on a server-owning service and hand-pick a distinct POSTGRES_USER, and its migration owners were superusers, so services were not isolated from each other. Closed in the 2026-10-27 clean-up on the owner's instruction. |
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.
Local compositions currently start a PostgreSQL server for every database service. This adds explicit sharing: an owned service with
shared-local-server: trueexports a local bootstrap capability; a database service withlocal-server: module/serviceconsumes that declared dependency while retaining its database, migrations, runtime principals and endpoint identity. Two database services can now run on one physical Nix or Docker server.Reuses Codefly's dependency graph, accepted Init mappings/configurations, lifecycle ordering, native/container runtimes, migrations and grant reconciliation. No machine-global pool, extra supervisor, fixed DSN or application-client changes. Default behavior is unchanged. Classification: fix in the Postgres runtime, which owns local database provisioning.
The borrower refuses absent/ambiguous dependency handoff, missing server opt-in, mismatched native addresses, a reused server-owner identity/database, incompatible server settings and PostgreSQL majors. Cluster-global role names have durable ownership claims; concurrent bootstrap is serialized with a bounded advisory lock. Runtime reader/writer principals cannot connect to peer databases. Migration owners remain trusted local superusers, as on the existing owned-cluster path; this is not isolation between untrusted migration authors. Stop/Destroy of a borrower never stops the dependency or drops data. The normal graph stops the server after consumers.
Validation:
go build ./...,go vet ./...,go mod tidy -diff,git diff --checkpassed.go test . -race -json -run '^Test(LocalServer|CIWorkflowEnforcesSharedServerRegression)' -count=1passed. Both real backends executed, neither skipped: Nix 3.63s, Docker 10.73s. Tests cover simultaneous independently migrated databases, published shared mappings, own-data reads, denied cross-database connections, role collision refusal, lock cancellation/retry, borrower Stop/Destroy and whole-server restart persistence.codefly agent buildinto an isolated plugin directory. Scaffolded a fresh workspace/module and three services withcodefly init/codefly add; composed two borrowers usingcodefly run service shared/alpha shared/beta --runtime-context nix. Both used one server listener. On SIGINT the CLI stopped both borrowers, then the server; verified the postmaster exited. No existing user database was migrated or deleted.-race. Workflow shape is tested. Actionlint passes with shellcheck disabled; full actionlint reports pre-existing SC2129 at line 41 in the unchanged image-resolution script.Docs updated:
docs/local-shared-server.mdcovers composition, trust boundaries, lifecycle/recovery, qualification and a deliberate backup/restore cutover.templates/agent/README.md.tmplexposes local sharing to scaffolded services;AGENTS.mdrecords the added CI regression.Limitations: opting in does not import an old per-service cluster. Directory's existing databases remain untouched. A standalone
codefly endpointinvocation unable to attach to the live flow can fall back to the borrower's proposed port; the composition's accepted mappings/runtime configuration are authoritative. Hosted manifests and external-instance bindings are unchanged; no hosted qualification or arbitrary application backup/restore was performed. The Docker test ran locally against the pinned published image; CI additionally runs it against the image built from this checkout.Fixes #193