Skip to content

Conversation

jrhe
Copy link

@jrhe jrhe commented Aug 5, 2025

Summary

Fixes PostgreSQL enum migration errors when dropping enum values that are used as column defaults.

Problem

When attempting to drop an enum value that is currently used as a default value for a column, PostgreSQL throws an error:

cannot drop type "enum_name" because other objects depend on it

This occurs because PostgreSQL cannot drop or modify an enum type while it's still referenced by a default constraint.

Solution

Added logic to drop default constraints before converting columns to text type during enum modifications. This ensures proper handling of dependencies when enum values are dropped.

Changes

  • Modified AlterTypeDropValueConvertor in sqlgenerator.ts to add DROP DEFAULT statements
  • Updated all affected tests to expect the new DROP DEFAULT statements
  • Added specific test case for the reported issue

Test plan

  • All existing enum tests pass with updated expectations
  • New test case specifically validates the fix for dropping enum values used as defaults
  • Migration generation correctly handles enum modifications with default values

Fixes #4295

🤖 Generated with Claude Code

When dropping enum values that are used as column defaults, PostgreSQL
throws an error "cannot drop type because other objects depend on it".
This fix adds DROP DEFAULT statements before modifying enum types to
properly handle the dependency.

Fixes drizzle-team#4295

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@jrhe
Copy link
Author

jrhe commented Aug 5, 2025

The singlestore tests failed as I do not have an API key. I haven't touched any singlestore related files so I think it should be ok, but would appreciate it if someone could double check.

PR co-authored with claude code but I ended up re-writing from scratch.

A large number of tests have been changed as this adds the DROP DEFAULT to any type that is being altered/dropped. From my testing, this should not cause issues when there is no default specified, and just do nothing. We would ideally only do it for those which had a default previously, but statement object does not include details of the previously default set on the enum, only the new one. I have looked into adding this to the diffing engine but I am not familiar enough with it to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Changing ENUM column with default value migration broken
1 participant