fix: use ALTER COLUMN instead of drop/create for type and length changes - #12754
fix: use ALTER COLUMN instead of drop/create for type and length changes#12754parastejpal987-cmyk wants to merge 2 commits into
Conversation
…p/create Signed-off-by: parastejpal987-cmyk <parastejpal987@gmail.com>
Code Review by Qodo
Context used 1. Cockroach enum ALTER invalid
|
Closes #3357
What changed?
Currently, if you change the
length,type, orisArrayproperty of an existing column, TypeORM's migration generator creates aDROP COLUMNandADD COLUMNquery. This causes silent and catastrophic data loss in production.This PR updates the
changeColumnimplementation for Postgres, CockroachDB, and Spanner. Instead of dropping the column, it now correctly generates anALTER TABLE ... ALTER COLUMN ... TYPE ...query for these modifications to preserve data. We fallback to the old drop/recreate behavior only if thegeneratedTypeexpression changes (since Postgres still requires a hard recreate for STORED generated columns).Testing
type/lengthupdates and correctly pushALTER COLUMNqueries in the drivers.