Skip to content

postgres: fail when the search path no longer resolves to the migrations table - #4397

Closed
AbhinavMir wants to merge 1 commit into
transact-rs:mainfrom
AbhinavMir:pg-detect-shadowed-migrations-table
Closed

postgres: fail when the search path no longer resolves to the migrations table#4397
AbhinavMir wants to merge 1 commit into
transact-rs:mainfrom
AbhinavMir:pg-detect-shadowed-migrations-table

Conversation

@AbhinavMir

Copy link
Copy Markdown

…ons table

The Postgres migrator refers to the migrations table by an unqualified
name. Postgres resolves that name through `search_path`, which contains
`"$user"` by default. Postgres ignores a search path entry that names no
existing schema. A migration that creates a schema with the name of the
database role therefore makes that schema shadow `public` in all later
sessions. The migrator then creates a second, empty migrations table and
applies every migration again.

`ensure_migrations_table()` now reads the effective search path with
`current_schemas(false)`. It then finds the schemas that hold the table.
The table can exist in the search path, but not in the schema that an
unqualified name resolves to. In that condition, migration stops with
the new `MigrateError::AmbiguousMigrationsTable`. The check does not run
for a table name that the user set, because that user controls how the
name resolves.
@AbhinavMir

Copy link
Copy Markdown
Author

Hi, sorry for opening this PR! Looking back at some other issues, it seems like the team might not be open to AI-assisted PRs, and I respect it! I used Claude Opus 4.8 to build this PR. Closing it now!

Reference: #199 (comment)

@AbhinavMir AbhinavMir closed this Aug 25, 2026
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