Enums #3192
AleksandrSherman
started this conversation in
Show and tell
Enums
#3192
Replies: 1 comment
-
Great work! Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In the recent release of [email protected], we've introduced extended support for handling PostgreSQL enums.
Key Updates:
Let's dive into each of these features! 👀
1. Adding Values Before or After in an Enum
This is a critical update for users who actively use enums.
As PostgreSQL documentation says:
This means that the order of values is significant, and now Drizzle-kit fully supports managing the order within enums 🎉
For example, if you already have an enum in your database and need to insert a new value:
Previously, Drizzle-kit would ignore the order and generate the SQL statement as:
This could lead to potential issues when adding values in the future.
Now, Drizzle-kit respects the order of enum values and generates the correct SQL statement:
2. Dropping Enum Types
Previously, Drizzle-kit did not generate SQL for dropping enum types, requiring users to manually run the statement. Now, Drizzle-kit automates this process.
Example of SQL statement:
💡Note: If the enum is used by any column, the database will throw an error
3. Removing a Value from an Enum
Imagine you are designing a database for an application that tracks user statuses. You start by defining an enum type
user_status
to standardize possible states for each user. Here’s how initial schema looks like:Visualization of
users
tableOver time, you decide that the
registered
status is no longer necessary and should be removed from the list of possible statuses for users.After removing
registered
, the updated enum values should only contain:However, removing a value from a PostgreSQL enum is tricky since PostgreSQL does not support this directly. Due to this limitation, Drizzle-kit follows a workaround strategy:
text
.Following SQL statements will be generated:
Result schema visualization
4. Renaming Enums
Renaming enums is now fully supported:
This will generate the following SQL statement:
5. Changing Enum Type Schema
Migrating enums across schemas is a breeze with Drizzle-kit:
This will generate the following SQL:
With these update, Drizzle-kit makes managing PostgreSQL enums more powerful and flexible
Beta Was this translation helpful? Give feedback.
All reactions