Skip to content

Disallow add_column_with_default with NOT NULL

What does this MR do?

This adds a rubocop to disallow usage of add_column_with_default ... allow_null: false to avoid prolonged lock situations. For discussion see #38060 (closed).

add_column_with_default... allow_null: false basically performs this in the end:

change_column_null(:table, :column, false)

This translates into:

ALTER TABLE table ALTER COLUMN column SET NOT NULL;

Which in turn exclusively blocks the table until it is sure there are no offending records.

We might want to make exceptions for small tables, but this is an individual decision. The cop here should basically trigger this conversation.

Does this MR meet the acceptance criteria?

Conformity

Edited by 🤖 GitLab Bot 🤖

Merge request reports