Repository navigation
fix(database-pgsql): read index columns back without postgres's quotes - #715
Merged
markshust merged 1 commit intoNov 25, 2026
Conversation
Collaborator
|
Thanks Etienne, this is a clean fix and the write-up made it easy to verify. The real-Postgres rollback test is exactly the right coverage. Merging as is. On the |
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.
Problem
PgSqlIntrospector::parseIndexColumns()takes the column names of an index frompg_indexes.indexdef. PostgreSQL quotes a name there whenever it has to: a reserved word, mixed case or an embedded quote. The parser keeps those quotes, so an index ongroupis introspected with the column"group".Matching indexes by name hides this most of the time. It shows up when a migration recreates a database index from what was introspected:
PgSqlGeneratorquotes the name again, and the statement fails.0.14's derived index names (#709) make that the normal upgrade path for admin-auth, whose
permissionstable indexesgroup. On an app that was on 0.13:The generated
down()containsand the rollback fails with
column ""group"" does not exist. Because the statements before it in the samedown()have already run,permissionsis left with neither index.Change
PgSqlIdentifier::unquote(), the inverse ofquote(): it strips the delimiters and undoubles embedded quotes, and returns anything PostgreSQL did not quote (a plain name, an index expression) unchanged.parseIndexColumns()unquotes each column it reads.Tests
PgSqlIntrospectorTest: anindexdefwith"group","la""bel","displayName"and a plain column comes back as['group', 'la"bel', 'displayName', 'status']. Failed before with the quotes kept.PgSqlIdentifierTest:unquote()undoesquote()for plain, reserved, mixed-case and delimiter names, and leaves unquoted names and expressions alone.ReservedWordIdentifiersTest(integration, real PostgreSQL): the fixture entity gets#[Index(['group', 'order'])]. The test renames that index, applies the generated diff, then itsgenerateDown(), and checks that the old index is back ongroupandorder. Failed before with exactly the error above.pestonpackages/databaseandpackages/database-pgsqlagainst PostgreSQL 17 fromtests/Integration/compose.ymlwithMARKO_INTEGRATION_REQUIRED=1: 1997 passed.phpcs,php-cs-fixer --dry-runandphpstan: clean.Not in this PR:
Migratorruns a migration's statements without a transaction, so a migration that fails halfway on PostgreSQL stays half applied, as the droppedpermissionsindex above shows. PostgreSQL could roll the whole migration back. Happy to look at that separately if you want it.