Repository navigation
feat(bff): WithPostgresManagedSchema for a migration-owned session table - #83
Merged
Merged
Conversation
NewPostgresStore always ran CREATE TABLE IF NOT EXISTS and CREATE INDEX IF NOT EXISTS. PostgreSQL checks CREATE on the schema, and table ownership for the index, before it checks existence, so a role holding only SELECT, INSERT, UPDATE and DELETE on a table created by migrations could not start the store (reproduced on PostgreSQL 16). WithPostgresManagedSchema() (additive; default unchanged) makes the store run no DDL. At start-up it checks that the table has the store's columns and that the role holds each of SELECT, INSERT, UPDATE and DELETE (one has_table_privilege call each: with a list it is true when any is held), so a missing grant fails at start-up, not at the first sign-in. The doc comment gives the migration's CREATE TABLE and CREATE INDEX. Closes #82 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GKRxaeYxyDhmt42cehLsGA
This was referenced Oct 4, 2026
Merged
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.
What and why
Closes #82.
bff.NewPostgresStorealways ranCREATE TABLE IF NOT EXISTSandCREATE INDEX IF NOT EXISTS. PostgreSQL checksCREATEon the schema, and table ownership for the index, before it checks whether the object exists. So a least-privilege BFF role, withUSAGEon the schema andSELECT, INSERT, UPDATE, DELETEon a migration-owned table, could not start the store. I reproduced it on PostgreSQL 16 with exactly Lakebridge's layout (schemabff,search_path=bff):The new option
bff.WithPostgresManagedSchema()is additive, and the default is unchanged:SELECT id, data, created_at, last_seen, deleted_at … LIMIT 0).SELECT,INSERT,UPDATEandDELETE, and fails naming the missing privilege. This goes beyond the issue's proposal: a role withoutDELETEwould otherwise start and only fail at the first sign-out. There is onehas_table_privilegecall per privilege, because given a list it returns true when any of them is held (verified on PostgreSQL 16).CREATE TABLEandCREATE INDEXthe migration must run. The table name stays an unqualified, checked identifier, so the schema comes from the role'ssearch_path.How it was tested
TestPostgresStore_ManagedSchema:<table>_last_seen_idxappears afterwards, which proves no DDL ran.TestPostgresStore_ManagedSchemaChecksTheTable:DELETE(allowed in PostgreSQL), and start-up fails namingDELETE.By hand, with a real CRUD-only role on PostgreSQL 16, in Lakebridge's exact layout:
permission denied for schema bff, as reported.Put,Get,DeleteandSweepcleanly.The scratch role and database were removed. CI's database role can't create roles, so this isn't an automated test; the two tests above cover the same paths.
go mod tidy && git diff --exit-code go.sumleavesgo.sumunchangedgo build ./...passesgo vet ./...passesgo test -race -count=1 -timeout=120s ./...passes (withTEST_DATABASE_URL; all 8PostgresStoretests run)golangci-lint run ./...(v2.14.0) reports no issuegovulncheck ./...: CI (the sandbox can't reach vuln.go.dev)A line is added under
## [Unreleased]inCHANGELOG.mdCompatibility
bff.WithPostgresManagedSchema() PostgresStoreOption.Release note: with the Go 1.27.1 requirement already on
main, this makes the next minor (v1.20.0) a real feature release. Lakebridge moves to Go 1.27.1 with it, as stated in #82.🤖 Generated with Claude Code
https://claude.ai/code/session_01GKRxaeYxyDhmt42cehLsGA
Generated by Claude Code