Per-service DB ownership: self-provisioning, no cross-schema reads#184
Merged
Conversation
…ngle db Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Makes fluent-api provision and own its own database concern inside the one shared Postgres — least-privilege runtime role plus a separate migration role, created by an idempotent bootstrap that runs before migrations. No more shared db/init SQL or cross-schema role grants. (Companion PRs in fluent-platform and fluent-ai.)
src/db/scripts/bootstrap.ts(new) — idempotently creates api_migrator (DDL, owns public) and api_user (least-privilege runtime), the pgboss schema, and default grants;identifiers/passwords are quoted server-side and all three URLs are asserted to target one DB.
docker-entrypoint.sh— runs bootstrap → migrate → seed → start; drizzle.config.ts migrates as the migration role (MIGRATIONS_DATABASE_URL).queue.ts— pg-boss createSchema: false so the runtime role needs no CREATE-on-database (schema is pre-created by bootstrap).db/init/01-init-db.sql(legacy roles + cross-schema reads); compose.yaml + .env.example inject BOOTSTRAP_/MIGRATIONS_/DATABASE_URL and move the runtime connectionoff the postgres superuser to api_user.
fapi.sh / fapi.ps1— Podman path uses the per-service role URLs;db:initruns the repo's own migrations + seeds; dropped the db/init initdb mount.Test plan
./fapi.sh clean && ./fapi.sh up→ bootstrap runs, migrations apply, server starts\duapi_user, api_migrator → both present; api_user is not superuser\dt→ tables presentcurl -f http://localhost:9999/health→ 200 (confirms api_user can read/write public, incl. BetterAuth tables)