Prevent failures when adding NOT NULL constraints with Atlas

by rotemtam
macOS ◆ xterm-256color ◆ zsh 95 views

Modifying nullable column to non-nullable might fail in case it contains NULL values. For example:

ALTER TABLE t MODIFY COLUMN c int NOT NULL;

The solution, in this case, is to backfill NULL values with a default value:

UPDATE t SET c = 0 WHERE c IS NULL; ALTER TABLE t MODIFY COLUMN c int NOT NULL;

Enforce this kind of safety using the Atlas GitHub Action: https://atlasgo.io/integrations/github-actions