Generate a migration file with two or more statements.
ALTER TABLE `user` ADD `name` varchar(255) NOT NULL;--> This runs successfully
ALTER TABLE `user` ADD CONSTRAINT `name_unique_idx` UNIQUE(`name`);--> This fails due to conflicting names (all names are '') at this point in time
Then execute this migration against a planetscale DB like so
import { drizzle } from "drizzle-orm/planetscale-serverless";
import { Client } from "@planetscale/database";
import { migrate } from "drizzle-orm/planetscale-serverless/migrator";
import { env } from "~/env.mjs";
console.log("Starting migration");
console.log("Creating DB connection");
const client = new Client({
url: env.DEV_DATABASE_URL,
});
const db = drizzle(client);
console.log("Running migrations");
const result = await migrate(db, { migrationsFolder: "migrations" })
.then(() => {
console.log("Migrations finished");
})
.catch((err) => {
console.error("Migrating produced an error: ", err);
});
console.log(result);
console.log("Finished migration");
The migration will fail due to the second statement
The effect of the first statement will still exist in the database. It isn't rolled back even though the migration failed. It appears that the migration didn't run within a single transaction.
Expected behavior
At step (4.) I expect the entire migration to be rolled back since it failed.
Environment & setup
A node.js program running against a Planetscale DB.
What version of
drizzle-orm
are you using?^0.30.2
What version of
drizzle-kit
are you using?0.21.4
Describe the Bug
Generate a migration file with two or more statements.
Then execute this migration against a planetscale DB like so
Expected behavior
At step (4.) I expect the entire migration to be rolled back since it failed.
Environment & setup
A node.js program running against a Planetscale DB.