drizzle-team / drizzle-kit-mirror

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

MySQL migration produce statements in the wrong order #334

Open valentin0h opened 5 months ago

valentin0h commented 5 months ago

Having a very similar issue to https://github.com/drizzle-team/drizzle-kit-mirror/issues/45

The following code change

mysqlTable(
     {
         id: serial('id').primaryKey(),

+        publicId: varchar('public_id', { length: 100 }).unique().notNull(),
+
         otherId: varchar('other_id', { length: 100 }).notNull(),

generates this migration file

ALTER TABLE `content_references` ADD CONSTRAINT `content_references_public_id_unique` UNIQUE(`public_id`);--> statement-breakpoint
ALTER TABLE `content_references` ADD `public_id` varchar(100) NOT NULL;%    

Env:

drizzle-kit 0.20.14 drizzle-orm 0.29.4 MySQL (PlanetScale)

amit13k commented 5 months ago

I am facing the same issue. The statement for the unique constraint is generated before the column creation statement in the migration file.