Skip to content

MG06 — ALTER COLUMN TYPE rewrites the table under a lock

Group: Migration safety · Auto-fixable: no

Changing a column’s type rewrites the table under an exclusive lock and can fail or lose data on an incompatible conversion. Add a new column, backfill, and swap over instead. A provable safe widening (e.g. int -> bigint, varchar(50) -> text), determined from the column’s type history across the whole migration set, is not flagged.

bad: ALTER TABLE t ALTER COLUMN c TYPE int; -- narrowing bigint -> int
ok: ALTER TABLE t ALTER COLUMN c TYPE bigint; -- widening int -> bigint

Disable this rule in banshee.toml:

[lint]
exclude = ["MG06"]

Or silence one line with -- noqa: MG06. See Linting.