drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.02k stars 553 forks source link

[BUG]: Cannot drop Unique Constraint MySQL #998

Open skusez opened 1 year ago

skusez commented 1 year ago

What version of drizzle-orm are you using?

0.28.1

What version of drizzle-kit are you using?

0.19.12

Describe the Bug

  1. Create a mysql table with a unique constraint
  2. Drizzle-kit push
  3. Delete the unique constraint
  4. Drizzle-kit push

The ORM attempts to do the following:

ALTER TABLEMyTableDROP CONSTRAINTMyTable_MyKey_key``

whereas it should be executing this:

ALTER TABLEMyTableDROP INDEXMyTable_MyKey_key``

This is preventing pushes to the DB and errors in the console.

Expected behavior

Key should be dropped and drizzle-kit should push without issues.

Environment & setup

Planetscale DB connection in node.js 18 environment

masonbrothers commented 10 months ago

I think we need to use something like this for MySQL if you are using foreign keys. I don't think PlanetScale supports them.

ALTER TABLE MyTable DROP FOREIGN KEY IF EXISTS MyTable_MyKey_key;
ALTER TABLE MyTable DROP INDEX IF EXISTS MyTable_MyKey_key;

Source: https://stackoverflow.com/a/18317774

moh682 commented 8 months ago

I'm also experiencing the same issue now. Foreign Keys are being supported by PlanetScale, the feature is currently in beta.