simplify-inflection: duplicate fields bug#3027
Conversation
|
|
Also there might be a similar issue with |
|
Interesting. The plugin does assume a naming convention for FK relations that your schema doesn't comply with (see: https://github.com/graphile/crystal/tree/main/graphile-build/graphile-simplify-inflection#incompatible-database-schemas ), but if the fix is this simple it seems reasonable (I've not dug through your reasoning yet). It will be a semver major change, but that's fine for an inflection package - most changes will be semver major. Please can you reproduce this issue with a test before the change, then we can see the diff afterwards? |
|
I'll make a proper minimal reproduction sometime this week. The aforementioned section of the docs is not very satisfying to me because we are simply trying to upgrade from v4 to v5, so changing up our schema isn't a viable solution. We have to hope that the updated plugins get us as close as possible to the same schema as before, and then pave over that with custom plugins. I think currently writing the compatibility plugin to bridge the new and the old behavior would be above my skill level with Postgraphile, though I personally can just run the patches from this PR, of course. That being said, I'm only convinced to file this as an issue by my reasoning on comparing the two versions 1-to-1. |
|
OK here is the repro: https://gist.github.com/maximsmol/b4b331c19d97d22d3bb1d512014ad7d3 Included:
Schemas were formatted with Prettier Note that V5 with unmodified |
|
Sorry I wasn't clear, I meant reproduce it by adding a test to our test suite: https://github.com/graphile/crystal/tree/main/graphile-build/graphile-simplify-inflection/tests Is that something you're able to take a look at? |
|
Yeah OK, got it. Should be pretty easy now that I have a reproducible example |
Signed-off-by: maximsmol <1472826+maximsmol@users.noreply.github.com>
|
I've added the test case, including the generated schemas and diff I also included the diff without this patch as Edit: redid |
Signed-off-by: maximsmol <1472826+maximsmol@users.noreply.github.com>
Description
There seems to be a mistake in translating the simplify-inflection plugin from v4 to v5.
This causes naming conflicts in cases where there are two foreign-key references to a table:
This seems to inflect as
with the simplify-inflection plugin.
Note, I didn't test the exact example, but it is a snippet from our actual schema with renamed tables/fields.
In the v4 version, the plugin compared
detailedKeystoforeignTable.In v5, the same code path goes through comparison between
foreignPk.attributesandrelation.remoteAttributes. Meanwhile,detailedKeyscomes fromrelation.localAttributes. Also note thatforeignPkcomes fromrelation.remoteResource.uniques.This means that we are essentially comparing
relation.remoteResource.uniquestorelation.remoteAttributes, while a direct translation from v4 would be a comparison betweenrelation.localAttributes(≈detailedKeys) andrelation.remoteResource.uniques(≈foreignTable).Additionally, it is easy to see that this comparison does not at all depend on the local side of the specific field we are considering. Both fields come from
relation.remote*fields, which explains why this would always produce the same name if the foreign-key target is the same.The argument for
singleRelationBackwardsis basically the same. With the schema above, it causes the issue on theuserstable:The same comparison can be made between the v5 and v4 code, except this time
detailedKeysshould berelation.remoteAttributes.Performance impact
No impact.
Security impact
No impact.
Checklist
yarn lint:fixpasses.yarn testpasses.RELEASE_NOTES.mdfile (if one exists).