README.md in strong_migrations-1.5.0 vs README.md in strong_migrations-1.6.0
- old
+ new
@@ -60,11 +60,11 @@
Potentially dangerous operations:
- [removing a column](#removing-a-column)
- [adding a column with a default value](#adding-a-column-with-a-default-value)
- [backfilling data](#backfilling-data)
-- [adding a stored generated column](#adding-a-stored-generated-column) [unreleased]
+- [adding a stored generated column](#adding-a-stored-generated-column)
- [changing the type of a column](#changing-the-type-of-a-column)
- [renaming a column](#renaming-a-column)
- [renaming a table](#renaming-a-table)
- [creating a table with the force option](#creating-a-table-with-the-force-option)
- [adding a check constraint](#adding-a-check-constraint)
@@ -77,10 +77,14 @@
- [adding a foreign key](#adding-a-foreign-key)
- [adding an exclusion constraint](#adding-an-exclusion-constraint)
- [adding a json column](#adding-a-json-column)
- [setting NOT NULL on an existing column](#setting-not-null-on-an-existing-column)
+Config-specific checks:
+
+- [changing the default value of a column](#changing-the-default-value-of-a-column)
+
Best practices:
- [keeping non-unique indexes to three columns or less](#keeping-non-unique-indexes-to-three-columns-or-less)
You can also add [custom checks](#custom-checks) or [disable specific checks](#disable-checks).
@@ -624,9 +628,39 @@
safety_assured do
execute 'ALTER TABLE "users" DROP CONSTRAINT "users_some_column_null"'
end
end
end
+```
+
+### Changing the default value of a column
+
+#### Bad
+
+Rails < 7 enables partial writes by default, which can cause incorrect values to be inserted when changing the default value of a column.
+
+```ruby
+class ChangeSomeColumnDefault < ActiveRecord::Migration[6.1]
+ def change
+ change_column_default :users, :some_column, from: "old", to: "new"
+ end
+end
+
+User.create!(some_column: "old") # can insert "new"
+```
+
+#### Good
+
+Disable partial writes in `config/application.rb`. For Rails < 7, use:
+
+```ruby
+config.active_record.partial_writes = false
+```
+
+For Rails 7, use:
+
+```ruby
+config.active_record.partial_inserts = false
```
### Keeping non-unique indexes to three columns or less
#### Bad