Open dcousineau opened 3 months ago
Hmm, yes, I see the problem but I admit that I am not sure where in the chain the bug lies. As with many other issues, I won't promise when I can get around to debugging it but I would like to fix this as it does appear to be a bug and not some out-of-scope feature request. If this is blocking you, a post-render hook is probably the easiest way to get around it
Sounds great. Except for me managing to stub my toes here kanel has been excellent to me.
I'll try the post render hook first just to bandaid the situation. If you have any examples handy (that aren't already in this repo) that would be helpful, but if not no worries!
I'll also keep you posted if I am able to debug or chase the issue down myself.
Something I just noticed because I bumped to 3.9.0
2 weeks ago (but hadn't had cause to re-run type generation) is I am now getting a lot of "Could not resolve circular reference" warnings (from this line: https://github.com/kristiandupont/kanel/blob/ace86e45955b2eca64b0f66a2a367b9a3cc50a30/packages/kanel/src/generators/resolveType.ts#L100) which was from #540 and the following error:
TypeError: Cannot read properties of undefined (reading 'join')
at writeFile (./node_modules/kanel/build/writeFile.js:41:27)
at ./node_modules/kanel/build/processDatabase.js:78:60
at Array.forEach (<anonymous>)
at processDatabase (./node_modules/kanel/build/processDatabase.js:78:18)
at async main (./node_modules/kanel/build/cli/main.js:120:9
(Upon further inspection the writeFile
method has a lines
argument set to undefined rather than an array)
So this is a clue at least, I can't spend much more time today digging in but I'll report back when I get the chance to spend more time on it.
It appears the issue stems from a parent FKEY referencing columns in a child who are themselves also an FKEY. I'm still unsure if the composite FKEY aspect comes into play.
TLDR Found possibly an edge case, possibly an issue on my end, involving composite foreign keys and would love guidance on next steps (fix my kanel configs? learn where in kanel this could be happening an help contribute a fix? wait for a fix?)
I have recently come across an issue where Kanel (+ Kanel-Kysely) generates problematic outputs as my schema has evolved to have more complex compound foreign keys. It's possible my configurations are bad or I'm doing something very silly.
The TLDR of the issue is when I have a moderately complex n:m type join table in situations where both sides of the join have composite primary keys. Kanel attempts to do an
OR
union of the "identifier" types (but for only one side of the equation) for identifier types it... doesn't actually create.Given the following postgres schema:
And a
.kanelrc.js
almost entirely based on https://github.com/kristiandupont/kanel/blob/main/example/.kanelrc.js, we get the following outputs.In an ideal world, Kanel would not attempt to create
BOrganizationId
nor would it attempt to union it withOrganizationId
.ABMatch.ts
B.ts