if any migration file have multiple line of statement, and if 3rd line cause any error to failed the migration then changes made by 1st and 2nd line on the database did not rollback. so next time when i try to fix the issue of 3rd line and rerun the migration got error on 1st and 2nd line that those are already applied.
how to reproduce the error
# clone the repo# install deps
pnpm i
# modify db connection url in .drizzle/migrator.ts file and src/db/db.ts# apply migrations to db
pnpm db:generate
pnpm db:deploy # base setup done
pnpm db:seed # it will create two row in user table with same full_name and created_at date, based on that we will get the error
now we will make some changes on the user schema to get error on drizzle kit deploy
updated schema (added gender and unique constraint)
ALTERTABLE`users` ADD CONSTRAINT`uq_id_time` UNIQUE(`full_name`,`created_at`);--> statement-breakpointALTERTABLE`users` ADD `gender` enum('male','female') DEFAULT 'male'NOT NULL;
-- just change the order of statement to have the error in 2nd line-- updated orderALTERTABLE`users` ADD `gender` enum('male','female') DEFAULT 'male'NOT NULL;--> statement-breakpointALTERTABLE`users` ADD CONSTRAINT`uq_id_time` UNIQUE(`full_name`,`created_at`);
Try to deploy those changes
pnpm db:deploy
it failed but if you see the user table on db now we can see there are gender field is there. which should not be there