Skip to content

fix(uuid): PostgreSQL-compatible partial-UUID resolution#3

Merged
eluhr merged 1 commit into
masterfrom
feature/postgres-partial-uuid
Jul 1, 2026
Merged

fix(uuid): PostgreSQL-compatible partial-UUID resolution#3
eluhr merged 1 commit into
masterfrom
feature/postgres-partial-uuid

Conversation

@eluhr

@eluhr eluhr commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Problem

UuidResolver::findByPartialBinaryUuid() built raw MySQL-only SQL:

SELECT BIN_TO_UUID(id) AS uuid_str FROM <t> WHERE LOWER(HEX(id)) LIKE :partialId LIMIT 2

On PostgreSQL the Symfony uuid type is a native uuid column (not
BINARY(16)), so HEX() / BIN_TO_UUID() don't apply and every partial-UUID
lookup failed with SQLSTATE[42883]: function bin_to_uuid(uuid) does not exist
→ HTTP 500 (e.g. the OAuth callback resolving a configuration by partial id).

Fix

Extract the lookup SQL into a public static buildPartialUuidSql(AbstractPlatform, $table, $idColumn)
that branches per platform:

  • PostgreSQL: SELECT id::text ... WHERE REPLACE(LOWER(id::text), '-', '') LIKE :partialId
  • MySQL/MariaDB: unchanged HEX() / BIN_TO_UUID() path

Both select the canonical hyphenated UUID and match the same hyphen-stripped
hex prefix. The id column is now resolved from metadata instead of hardcoded.

Test

Adds UuidResolverTest asserting the generated SQL per platform (PostgreSQL
uses id::text/REPLACE and no BIN_TO_UUID; MySQL uses HEX/BIN_TO_UUID) —
no database required. Verified end-to-end against PostgreSQL 15 in the consuming
ZA7 application (full functional suite green).

🤖 Generated with Claude Code

UuidResolver::findByPartialBinaryUuid built raw MySQL-only SQL
(`SELECT BIN_TO_UUID(id) ... WHERE LOWER(HEX(id)) LIKE ...`). On
PostgreSQL, where the Symfony `uuid` type is a native `uuid` column
(not BINARY(16)), this threw `function bin_to_uuid(uuid) does not exist`
and every partial-UUID lookup returned HTTP 500.

Extract the lookup into a public static buildPartialUuidSql() that
branches on the platform: `id::text` + REPLACE on PostgreSQL, HEX() +
BIN_TO_UUID() on MySQL/MariaDB. Both yield the canonical UUID string and
match the same hyphen-stripped hex prefix. Also resolve the id column via
metadata instead of hardcoding "id".

Adds UuidResolverTest asserting the generated SQL per platform.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@eluhr eluhr merged commit 287d53c into master Jul 1, 2026
2 checks passed
@eluhr eluhr deleted the feature/postgres-partial-uuid branch July 1, 2026 15:23
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