drizzle-team / drizzle-kit-mirror

Docs and issues repository for drizzle-kit
289 stars 17 forks source link

Unable to create index concurrently with migration and postgres #486

Open thedewpoint opened 3 months ago

thedewpoint commented 3 months ago

I have created an index using drizzle

export const transformers = pgTable('transformers', {
    id: uuid('id').primaryKey(),
    name: transformerNameEnum('name').notNull(),
    workflowId: uuid('workflow_id').notNull().references(() => workflows.id)
},
    (transformers) => ({
        workflowIdIdx: index('transformer_workflow_id_idx').on(transformers.workflowId).concurrently(),
    })
);

which generates the below SQL

--> statement-breakpoint
CREATE INDEX CONCURRENTLY IF NOT EXISTS "transformer_workflow_id_idx" ON "transformers" USING btree ("workflow_id");

When I run migrate using drizzle-kit, it gives the following error: error: CREATE INDEX CONCURRENTLY cannot run inside a transaction block

I can't find a way to disable transactions for this migration, my alternative is to not use concurrently which isn't a great option

thedewpoint commented 3 months ago

looks to be the same issue opened here : https://github.com/drizzle-team/drizzle-orm/issues/860

kenn commented 2 months ago

Yep, it started to happen recently. (drizzle-kit 0.23, drizzle-orm 0.32) with pg adapter.

Before:

CREATE INDEX IF NOT EXISTS ...

After:

CREATE INDEX CONCURRENTLY IF NOT EXISTS ...

and this causes error with npx drizzle-kit migrate. Maybe pg adapter uses transaction in the migrate command?