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
rushil1o1OPā€¢2y ago
Andrii Sherman
Andrii Shermanā€¢2y ago
Thanks Will patch release this fix today and ping you So, quotes were fixed in [email protected]. 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
rushil1o1OPā€¢2y ago
rushil1o1
rushil1o1OPā€¢2y ago
@Andrii Sherman
Andrii Sherman
Andrii Shermanā€¢2y ago
Ok, great! Thanks for the details Working on it
rushil1o1
rushil1o1OPā€¢2y 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
rushil1o1OPā€¢2y ago
Andrii Sherman
Andrii Shermanā€¢2y ago
did you install [email protected]?
rushil1o1
rushil1o1OPā€¢2y ago
yep
rushil1o1
rushil1o1OPā€¢2y ago
plus ran yarn install to update @Andrii Sherman any updates @Andrii Sherman?
Andrii Sherman
Andrii Shermanā€¢2y ago
yeah, still didn't have a chance to look at it will ping right after I'll check it and fix
rushil1o1
rushil1o1OPā€¢2y ago
perfect thanks!
Andrii Sherman
Andrii Shermanā€¢2y ago
@rushil1o1 [email protected] should have all fixes with escape characters. Just try to regenerate migrations Defaults for arrays still in progress
rushil1o1
rushil1o1OPā€¢2y ago
thank you so much! will check it out
rushil1o1
rushil1o1OPā€¢2y 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ā€¢2y ago
@bloberenober
Dan
Danā€¢2y ago
The pgEnum issue will be fixed, but for spreading you can get the columns from getTableConfig() and operate on them
rushil1o1
rushil1o1OPā€¢2y 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 āš”ā€¢2y 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 šŸ¤”
Dan
Danā€¢2y ago
DB enums are not very convenient in the first place, which is why we introduced the "text enums" as an alternative
rphlmr āš”
rphlmr āš”ā€¢2y ago
That's what I missed in Prisma: literals. Now it changes everything If nobody manually add records in DB :p
Dan
Danā€¢2y ago
Well, you can always add check constraints @rushil1o1 the pgEnum issue was fixed in 0.23.6
rushil1o1
rushil1o1OPā€¢2y 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
Dan
Danā€¢2y ago
it shouldn't be an issue since we escape all names, was just a bug in the query generation
rushil1o1
rushil1o1OPā€¢2y ago
nice!
Want results from more Discord servers?
Add your server