Bug: drizzle-kit generate:pg didn't see the changes in the schema
On my uniqueIndex i added a where clause to not check the soft delete records. When running generate, the drizzle-kit didn't generate any migration since it thinks i haven't modified the schema.
8 Replies
After I deleted the migrations folder and rerun the generate function, the migration was not correctly generated. The where clause was missing.
CREATE UNIQUE INDEX IF NOT EXISTS "sku_workspace_products_itemsuniquekey" ON "products_items" ("sku","workspace_id");--> statement-breakpoint
When adding it manually in the database as:
create unique index sku_workspace_products_itemsuniquekey on public.products_items using btree (sku, workspace_id) where deleted_at IS NULL;
it works like a charm. So it seems that it's not seeing the where clause to generate the schema from. Am I missing something?
Can you confirm that it's 100% seeing this file?
yea, I just removed the migration folder again after your message and ran drizzle-kit generate:pg and it just created the same unique index without the where clause
Also it's the only schema i have declared in my project
Could you share the whole table declaration + schema file if you have one? I haven't personally had this issue before, but something is bound to jump out at me
Also i did some research and I saw this opened issue on github for this problem
https://github.com/drizzle-team/drizzle-kit-mirror/issues/47
GitHub
[BUG]: uniqueIndex not respecting WHERE clause in postgres · Issue ...
What version of drizzle-orm are you using? 0.25.4 What version of drizzle-kit are you using? 0.17.6 Describe the Bug in my schema, I have: indexWithWhere: uniqueIndex("index_with_where") ...
Well, seems like it's not supported right now, not sure what else I can do here tbh
Not supported in drizzle-kit right now, but will work on that soon
Have a lot of things to finish, so sorry for delays on some feature requests we have
Is there a way around this for now? @Andrew Sherman