Unique keys aren't able to be reconciled properly using Drizzle with PlanetScale MySQL.
We have unique constraints defined using Drizzle Orm, either through the primary key constructor, or through specific unique key constructors i.e
id: serial('id').primaryKey(),
or (and see my comment above the code)
/*
- this will always cause an error to throw when running yarn db:push against your feature db
- your changes should get any other changes you've made should be applied anyway
- think its an error with the drizzle push command not reconciling the constraint properly
*/
email: varchar('email', {length: 255}).notNull().unique(),
We use DDL against feature branches in PlanetScale to create a schema change, then make a deploy request to PlanetScale.
A few things are happening:
When we push unrelated schema changes to our DB using drizzle-kit push --config=drizzle.config.ts - we get an error complaining the above constraint already exists i.e You're about to add users_email_unique unique constraint
When we make deploy requests after adding unrelated tables/column changes, we'll find that Unique Keys from random tables are being dropped
Expected behavior
Unique keys are able to be reconciled properly through introspection
Unique keys wouldn't randomly be dropped through DDL commands against our planetscale feature branches, through unrelated changes
What version of
drizzle-orm
are you using?0.31.2
What version of
drizzle-kit
are you using?0.22.8
Describe the Bug
Unique keys aren't able to be reconciled properly using Drizzle with PlanetScale MySQL.
We have unique constraints defined using Drizzle Orm, either through the primary key constructor, or through specific unique key constructors i.e
or (and see my comment above the code)
We use DDL against feature branches in PlanetScale to create a schema change, then make a deploy request to PlanetScale.
A few things are happening:
drizzle-kit push --config=drizzle.config.ts
- we get an error complaining the above constraint already exists i.eYou're about to add users_email_unique unique constraint
Expected behavior
Environment & setup
Node JS: 20.14.0