BUG: Postgres migration script generates a few syntax errors

Context: I was running migrations with drizzle-kit's migration function from node-postgres , and kept getting a lot of errors. I had to make the following changes to the SQL script: 1. Add double quotes around table, index, and other field names 2. Array fields with default values just never generated the right code. So I had to manually add the default value in. Screenshots show the full picture
25 Replies
rushil1o1
rushil1o1ā€¢16mo ago
Andrii Sherman
Andrii Shermanā€¢16mo ago
Thanks Will patch release this fix today and ping you So, quotes were fixed in drizzle-kit@0.17.1-4d93888. You can check it Could you please show how ts schema looks like for array column? Simple row should be enough. Want to know how default was defined(if it was). It will help me to spot an issue faster Right after I'll fix default for array - I'll release patch fix to latest
rushil1o1
rushil1o1ā€¢16mo ago
rushil1o1
rushil1o1ā€¢16mo ago
@Andrii Sherman
Andrii Sherman
Andrii Shermanā€¢16mo ago
Ok, great! Thanks for the details Working on it
rushil1o1
rushil1o1ā€¢16mo ago
thanks ! @Andrii Sherman ! FYI @Andrii Sherman I checked out the latest version and got a migration file generated that didn't have double quotes. See screenshot attached
rushil1o1
rushil1o1ā€¢16mo ago
Andrii Sherman
Andrii Shermanā€¢16mo ago
did you install drizzle-kit@0.17.1-4d93888?
rushil1o1
rushil1o1ā€¢16mo ago
yep
rushil1o1
rushil1o1ā€¢16mo ago
plus ran yarn install to update @Andrii Sherman any updates @Andrii Sherman?
Andrii Sherman
Andrii Shermanā€¢16mo ago
yeah, still didn't have a chance to look at it will ping right after I'll check it and fix
rushil1o1
rushil1o1ā€¢16mo ago
perfect thanks!
Andrii Sherman
Andrii Shermanā€¢16mo ago
@rushil1o1 drizzle-kit@0.17.4 should have all fixes with escape characters. Just try to regenerate migrations Defaults for arrays still in progress
rushil1o1
rushil1o1ā€¢16mo ago
thank you so much! will check it out
rushil1o1
rushil1o1ā€¢16mo ago
Tested it and it works perfectly. Unfortunately, we can't use it yet - 0.22.0 -> 0.23.0 had some breaking changes for us syntactically. Spread operator on select is deprecated (?) Getting the following error:
Property 'brand' is incompatible with index signature.
Type 'string' is not assignable to type 'AnyPgColumn<{}> | SQL<unknown> | Aliased<unknown>'.ts(2345)
Property 'brand' is incompatible with index signature.
Type 'string' is not assignable to type 'AnyPgColumn<{}> | SQL<unknown> | Aliased<unknown>'.ts(2345)
Also, pgEnum.enumValues changed from TValues to string[] which is throwing inference errors for us. šŸ˜¦ @Andrii Sherman
Andrii Sherman
Andrii Shermanā€¢16mo ago
@bloberenober
bloberenober
bloberenoberā€¢16mo ago
The pgEnum issue will be fixed, but for spreading you can get the columns from getTableConfig() and operate on them
rushil1o1
rushil1o1ā€¢16mo ago
Thanks @bloberenober , @Andrii Sherman That helps --- We'll probably upgrade once the enum issue is fixed. The migration issue is a non-blocker for us and we can just continue to manually annotate migrations with double quotes FYI: here's our enum workaround - https://discord.com/channels/1043890932593987624/1090155866789007380
rphlmr āš”
rphlmr āš”ā€¢16mo ago
this is maybe why I ended with what I shared in your previous post šŸ˜…. works fine like that but Iā€™m thinking of removing db enums šŸ¤”
bloberenober
bloberenoberā€¢16mo ago
DB enums are not very convenient in the first place, which is why we introduced the "text enums" as an alternative
rphlmr āš”
rphlmr āš”ā€¢16mo ago
That's what I missed in Prisma: literals. Now it changes everything If nobody manually add records in DB :p
bloberenober
bloberenoberā€¢16mo ago
Well, you can always add check constraints @rushil1o1 the pgEnum issue was fixed in 0.23.6
rushil1o1
rushil1o1ā€¢16mo ago
thank you so much! @bloberenober - will check it out soon! all good - everything works! -- tested the new migration as well; @Andrii Sherman @bloberenober in hindsight - we should have kept our DB models // attributes in snake case - (since SQL defaults to that if you don't use quotes) lol
bloberenober
bloberenoberā€¢16mo ago
it shouldn't be an issue since we escape all names, was just a bug in the query generation
rushil1o1
rushil1o1ā€¢16mo ago
nice!
Want results from more Discord servers?
Add your server
More Posts