Open MatanYadaev opened 1 year ago
Did you figured it out?
Any update on this ?
This is still an issue. Removed a value from my enum, No schema changes, nothing to migrate 😴
Still an issue
I think the idea to generate a bunch of custom queries that handle all (or some) cases for when we change a type in drizzle, it should be roughly something like this: 1) rename the changed type to something else 2) create new type with the new changes 3) assign that type to every column where it's used, it could be in multiple tables 4) drop the renamed type in 1.
Issues could arise where a certain value from the old type is being used in db that it can't be casted to the newer type values or if we have DEFAULT value
constraint being set on certain columns which needs to be dropped first before changing the column type.
We could automate generating such queries or just write them manually:
-- 01_migration.sql
CREATE TYPE "your_type" AS ENUM('FIRST', 'SECOND', 'THIRD', 'FRTH');
ALTER TABLE "your_table" ADD COLUMN "your_column" "your_type";
-- 02_migration.sql
ALTER TYPE "your_type" RENAME TO "your_type_old";
CREATE TYPE "your_type" AS ENUM('FIRST', 'SECOND', 'THIRD');
ALTER TABLE "your_table" ADD COLUMN "your_column" "your_type";
DROP TYPE "your_type_old";
As of "drizzle-orm": "^0.32.0"
.
This issue still exists. No drop enums in migrations.
Encountered this as well, but then discovered this warning from the Supabase docs:
https://supabase.com/docs/guides/database/postgres/enums#removing-enum-values
So I wonder if this is somewhat intended behavior - or at least a recognition that removing enum values could create problems?
Interesting point @patrickdevivo , but IMO the ORM should have a consistent schema overtime.
If an enum is dropped from your schema, but not as part of your db migration (which is the current behavior).
Then overtime there the schema on db will deviate to an extend. If you want to do some schema debugging or recreate then the pg_dump
will differ which could raise false alarms.
Still an issue with PG enums...
What version of
drizzle-orm
are you using?0.28.5
What version of
drizzle-kit
are you using?0.19.13
Describe the Bug
When adding a new
pgEnum
to the schema, and runningdrizzle-kit generate:pg
, it generates a new SQL migration, but when removing thispgEnum
and running the same command, it doesn't do anything.Reproduction steps:
Add the
pgEnum
to the schema:Running
drizzle-kit generate:pg
:Removing the
pgEnum
:Running
drizzle-kit generate:pg
:Expected behavior
The last command execution should create a new SQL migration:
Environment & setup
Mac OS 13.5 Node 20 Postgres 15.3