Skip to content

Detect object ownership drift#291

Draft
dilame wants to merge 1 commit into
stripe:mainfrom
dilame:fix/object-ownership-drift
Draft

Detect object ownership drift#291
dilame wants to merge 1 commit into
stripe:mainfrom
dilame:fix/object-ownership-drift

Conversation

@dilame
Copy link
Copy Markdown

@dilame dilame commented Jun 1, 2026

Summary

  • Introspect role ownership for supported schema objects: tables, functions, procedures, enum types, sequences, views, and materialized views.
  • Emit ALTER ... OWNER TO ... for owner drift, with authz hazards on owner changes.
  • Preserve target owners when creating new objects, because the migration execution role may differ from the desired owner.
  • Add acceptance coverage for each supported object kind and update schema hash fixtures for the new owner fields.

Root Cause

pg-schema-diff did not include object owners in its schema model, so source/target ownership drift could survive an otherwise clean migration plan.

Validation

PATH=/Applications/Postgres.app/Contents/Versions/16/bin:$PATH go test ./... -count=1

Track role ownership for supported schema objects so plan generation emits ALTER ... OWNER TO instead of accepting ownership drift silently.

Constraint: production drift checks need declarative owner alignment rather than manual repair SQL after migration planning.

Rejected: fixing only table owners | functions, procedures, enum types, sequences, views, and materialized views have the same drift failure mode.

Confidence: high

Scope-risk: moderate

Directive: create-time owner DDL should remain explicit because the migration execution role may not be the target object owner.

Tested: PATH=/Applications/Postgres.app/Contents/Versions/16/bin:/opt/local/bin:/opt/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/go/bin:/Users/bowzee/.volta/bin:/Users/bowzee/.codex/tmp/arg0/codex-arg092ZG6R:/opt/homebrew/share/google-cloud-sdk/bin:/Users/bowzee/perl5/bin:/Users/bowzee/.antigravity/antigravity/bin:/opt/homebrew/opt/libpq/bin:/Users/bowzee/.local/bin:/opt/local/bin:/opt/local/sbin:/Users/bowzee/.cargo/bin:/Users/bowzee/Library/Application Support/JetBrains/Toolbox/scripts:/Applications/Codex.app/Contents/Resources go test ./... -count=1
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