Repository navigation
Replies: 4 comments
|
Actually the real issue you will encounter if the same PR deletes the column from the Drizzle schema + creates the migration to drop it is not about typings, but about the SQL that Drizzle will generate. Assuming that the schema migration is run first and then only the new code is deployed, between these two events, any |
|
I'm running into the same issue with dropping columns in a safe way. When I remove a column from the schema, that will cause a migration to be generated when I run One hack that I've used is to do this in two steps:
This is harder than it should be and support for this in drizzle would be helpful (even a guide section in the docs on how to safely do migrations would help) |
|
A workaround is to do it in two steps:
I still think some option to deprecate a column would be nice, it would achieve the first PR at the schema level, which would be less tedious and give stronger guarantees than "I think we're not using it anymore". |
|
What you're describing is a schema/code-generation concern rather than a database-level deprecation. I checked the current Drizzle documentation and repository discussions. Drizzle currently treats the TypeScript schema as the source of truth for migration generation, so removing a column from the schema naturally causes drizzle-kit to interpret it as a database change. I also found a GitHub Discussion that is essentially the exact feature request you're describing: “Deprecating some columns from a Drizzle schema.” The proposed workflow is the same three-step process you outlined, and the author specifically suggested something like $deprecated() so the column disappears from TypeScript types without causing Drizzle Kit to generate a DROP COLUMN. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
When deleting a column from a table (to replace it with another column), my process is:
It would be nice if PR2 didn't have to delete the old column from the schema to ensure that the application code doesn't use it anymore. Instead, it could use some kind of setting on the old column, that allows "deprecating" it. It would mean that the column is not visible anymore in the table's typescript type, but
drizzle-kitwouldn't generate a migration to drop it. Something like:description: text('description').$deprecated()The reason I'm suggesting this is that I find it awkward to accept that in some situations, there is a difference between the typescript schema and the DB schema. We try to run some tests as part of our CI to prevent people from merging things when such a discrepancy exists (the test generates a schema migration, and returns a failure if it was able to generate it). Some option to flag the columns where this discrepancy is expected would be useful.
I looked for this in the docs, but maybe I searched a bit too specifically for deletion of columns, and should have been looking for manipulating types in general?
Thanks for reading, and for maintaining a great tool!
All reactions