drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
21.47k stars 486 forks source link

[BUG]: Recreating pg index in version 0.31(orm) + 0.22(kit) fails #2470

Closed AlonMiz closed 3 weeks ago

AlonMiz commented 3 weeks ago

What version of drizzle-orm are you using?

0.31.1

What version of drizzle-kit are you using?

0.22.4

Describe the Bug

after migrating to v0.31 it tries to recreate the indexes I have (pg)

The generated migration

DROP INDEX IF EXISTS "orgIdIndex";--> statement-breakpoint
DROP INDEX IF EXISTS "cardTypeIdIndex";--> statement-breakpoint
DROP INDEX IF EXISTS "nameIndex";--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "orgIdIndex" ON "Cards" USING btree (orgId);--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "cardTypeIdIndex" ON "Cards" USING btree (cardTypeId);--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "nameIndex" ON "Cards" USING btree (name);

Error

CREATE INDEX IF NOT EXISTS "orgIdIndex" ON "Cards" USING btree (orgId);
🛢 rollback
🛢  DB - Database migration failed error: column "orgid" does not exist
    at /node_modules/pg/lib/client.js:526:17
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /.next/server/chunks/node_modules_drizzle-orm_9f263b._.js:4065:25
    at async NodePgSession.transaction (/.next/server/chunks/node_modules_drizzle-orm_9f263b._.js:5900:28)
    at async PgDialect.migrate (/.next/server/chunks/node_modules_drizzle-orm_9f263b._.js:4061:9)
    at async migrate (/.next/server/chunks/node_modules_drizzle-orm_9f263b._.js:69:5)
    at async migrateDb (/.next/server/chunks/_0508b7._.js:1474:9)
    at async POST (/.next/server/chunks/_0508b7._.js:1516:9)
    at async /node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:53446

my guess is that the query executes with lowercase, and my column is mixed. (orgId !== orgid)

Expected behavior

i would expect the recreation of the index to succeed

Environment & setup

mac + next js 14+ pg + drizzle

AndriiSherman commented 3 weeks ago

fixing!

AndriiSherman commented 3 weeks ago

Should be fixed in drizzle-kit@0.22.5

AlonMiz commented 3 weeks ago

Wow! Thanks @AndriiSherman you are doing some great work! 🙏