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.85k stars 593 forks source link

[BUG]: Postgres - Cannot rename ENUM columns on schema change #1409

Open Ali-Parandeh opened 12 months ago

Ali-Parandeh commented 12 months ago

What version of drizzle-orm are you using?

0.28.5

What version of drizzle-kit are you using?

0.19.13-e99bac1

Describe the Bug

I'm using Payload

https://payloadcms.com/

I was trying to split a flat collection that contains a SELECT field into a collection with two tabs. If there is already data in the database, the migration fails and also hangs the server with a node error because of the select field.

I get asked to rename the columns of the collection one by one to reflect the fields being nested inside tabs now but the SELECT field cannot be renamed if it already has data in its column. Postgres won't allow the rename because of the ENUM constraint.

Expected behavior

The rename column wizard should be able to rename ENUM columns without problem even if it has to truncate the table.

Environment & setup

  1. Make sure to have the postgres version of payload installed with a local postgres db
  2. Create a flat collection that contains a select field
  3. Populate a few records in this collection via the admin UI
  4. Now change the schema of the collection to split fields into two tabs (using tab fields)
  5. Payload now should ask you to rename db columns via the CLI
  6. Accept column renames and you will get a postgres migration error because of the ENUM column constraint not being resolved (even if you accept data loss)
Ali-Parandeh commented 12 months ago

Related to: https://github.com/payloadcms/payload/issues/3807

L-Mario564 commented 1 day ago

@Ali-Parandeh Hey there. Is this still an issue in the latest versions of ORM and Kit?