Skip to content

MG03 — ADD COLUMN with a volatile DEFAULT rewrites the whole table

Group: Migration safety · Auto-fixable: no

A volatile default (now(), random(), gen_random_uuid(), …) is evaluated per row, forcing a full table rewrite under a lock. Add the column without a default, backfill in batches, then set the default for new rows.

bad: ALTER TABLE t ADD COLUMN c uuid DEFAULT gen_random_uuid();
good: ALTER TABLE t ADD COLUMN c uuid; -- then backfill

Disable this rule in banshee.toml:

[lint]
exclude = ["MG03"]

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