Repository navigation
Conversation
Relation joins use path-derived aliases such as `__root_<relation>_rel_<nested>_rel`. With long
relation names these exceed the 63 character identifier limit of Postgres, which silently
truncates them, so two joins sharing a long prefix end up with the same alias ("table name ...
specified more than once"), and the long aliases of the EXISTS subqueries for relation filters
can no longer be resolved.
Aliases longer than the driver's maxAliasLength are now cut and suffixed with a short hash of
the full alias. The shortening is applied wherever a join alias is created or referenced
(relations, config where, polymorphic filters, relation filter subqueries and fixColumnAlias),
so every reference to the same path resolves to the same alias. Aliases within the limit are
unchanged.
Fixes ppetzold#1172
alias-length.spec.ts opened its own data source on the same database with
dropSchema and synchronize. Jest runs spec files in parallel, so on MariaDB
it dropped the cat tables while paginate.spec.ts was running ("Table
'test.cat_friends_cat' doesn't exist").
Register the long alias entities with the paginate.spec.ts data source and
move the database tests there. alias-length.spec.ts keeps the getJoinAlias
unit tests, which need no database.
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.
Fixes #1172
What
Relation joins get path-derived aliases (
__root_<relation>_rel_<nested>_rel, and_rel_<name>_<depth>_<path>inside the EXISTS subqueries for relation filters). Long relation names push these past the 63-character identifier limit of Postgres. Postgres silently truncates them, so:table name "__root_relationWithAnExceptionallyLongNameThatOverflowsTheAlias" specified more than oncemissing FROM-clause entry for table "_rel_targetsReachedThroughAVeryLongRelationName_0_targetsReache"How
A new
getJoinAlias(qb, alias)helper returns the alias unchanged when it fits the driver'smaxAliasLength(63 on Postgres and MySQL/MariaDB, no limit on SQLite). When the alias is too long, it cuts it and appends an 8-character hash of the full alias, so the result is deterministic and distinct. Every place that creates or references a join alias uses the helper on the full path-derived alias:fixColumnAliasaddRelationsFromSchemawhere~) filter joinsThat way, each reference to a given path resolves to the same alias. Short aliases don't change, so existing queries are unaffected.
Tests
src/__tests__/long-alias.entity.tsadds entities whose relation names produce aliases over 63 characters. They are registered with thepaginate.spec.tsdata source, and a newjoin aliases longer than the database identifier limitblock there covers loading, sorting, filtering and searching two such relations (plus a nested one), to-many/EXISTS filters, a nested configwhere, and a polymorphic filter.src/alias-length.spec.tshas unit tests forgetJoinAlias. (The database tests started out in their own spec file with their own data source, butdropSchemathere racedpaginate.spec.tson the shared MariaDB database in CI, so they now share its data source.)DB=postgres, all 4 query tests fail with the errors above.I didn't run the MariaDB suite locally. The test entities use short join column names so their tables fit MariaDB's 64-character column limit.