Skip to content

Fix URI collation migration on PostgreSQL - #928

Closed
niektenhoopen wants to merge 1 commit into
putyourlightson:developfrom
niektenhoopen:fix/pgsql-uri-collation-migration
Closed

niektenhoopen wants to merge 1 commit into
putyourlightson:developfrom
niektenhoopen:fix/pgsql-uri-collation-migration

Conversation

@niektenhoopen

Copy link
Copy Markdown

The m261010_120000_make_uri_comparisons_sensitive migration in 5.14.0 fails on PostgreSQL:

SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "{{%blitz_caches}}" does not exist

The update is rolled back and the migration stays pending, so the site responds with 503 until it is resolved.

Cause

In the PostgreSQL branch, the table name is bound as a parameter of CAST(:table AS regclass). CacheRecord::tableName() returns {{%blitz_caches}}, and Schema::quoteTableName() returns names containing {{ unchanged. The {{%...}} placeholder is only resolved in the SQL string, not in parameter values, so PostgreSQL receives the literal placeholder.

Fix

Bind $tableSchema->fullName instead. The table schema is already loaded at the top of the migration, and its fullName is the resolved name with the table prefix applied (and the schema prepended when it is not the default schema).

Testing

  • Reproduced the error on Craft 5.11.5.1, PHP 8.5, PostgreSQL 13 by updating from 5.13.4 to 5.14.0 and running craft migrate/all.
  • With this change, the migration applies. Afterwards the uri column has collation C, and is still varchar(2048) NOT NULL. A second craft up finds nothing pending.
  • Added a Pest test for the PostgreSQL branch, next to the existing MySQL one. The tests in UriCollationMigrationTest.php pass, and the new test fails against the unpatched migration.

The table name was bound as a parameter while still containing the
{{%table}} placeholder, which is only resolved in the SQL string, so
the regclass cast failed with an undefined relation.
@bencroker bencroker closed this Oct 15, 2026
@niektenhoopen
niektenhoopen deleted the fix/pgsql-uri-collation-migration branch October 15, 2026 13:34
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.

2 participants