shlogg · Early preview
Jackson Kasi @jacksonkasi11

Fixing DO $$ Blocks In Drizzle ORM Migrations On Nile Postgres

Drizzle ORM on Nile Postgres? Remove DO $$ blocks to fix migration issues. Keep ALTER TABLE statements, simplify operations. Works by assuming clean database or managing errors separately.

When working with Drizzle ORM on a Nile Postgres database, you might encounter an issue where the migration fails due to the use of DO $$ blocks. This is because Nile Postgres does not currently support DO $$ statements. Here's a simple guide to fix this issue and make your migrations work.



  
  
  What’s the Problem?

Drizzle ORM sometimes generates SQL with DO $$ blocks for operations like adding foreign key constraints. Here’s an example:

DO $$ BEGIN
 ALTER TABLE "account" ADD CONSTRAINT "account_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE no act...