README.md in strong_migrations-0.1.8 vs README.md in strong_migrations-0.1.9
- old
+ new
@@ -50,11 +50,14 @@
add_column :users, :some_column, :text
# 2
commit_db_transaction
- # 3
+ # 3.a (Rails 5+)
+ User.in_batches.update_all some_column: "default_value"
+
+ # 3.b (Rails < 5)
User.find_in_batches do |users|
User.where(id: users.map(&:id)).update_all some_column: "default_value"
end
# 4
@@ -140,10 +143,18 @@
safety_assured { remove_column :users, :some_column }
end
end
```
+## Existing Migrations
+
+To mark migrations as safe that were created before installing this gem, create an initializer with:
+
+```ruby
+StrongMigrations.start_after = 20170101000000
+```
+
## Dangerous Tasks
For safety, dangerous rake tasks are disabled in production - `db:drop`, `db:reset`, `db:schema:load`, and `db:structure:load`. To get around this, use:
```sh
@@ -163,9 +174,17 @@
Columns can flip order in `db/schema.rb` when you have multiple developers. One way to prevent this is to [alphabetize them](https://www.pgrs.net/2008/03/13/alphabetize-schema-rb-columns/). Add to the end of your `Rakefile`:
```ruby
task "db:schema:dump": "strong_migrations:alphabetize_columns"
+```
+
+## Analyze Tables (Postgres)
+
+Analyze tables automatically (to update planner statistics) after an index is added. Create an initializer with:
+
+```ruby
+StrongMigrations.auto_analyze = true
```
## Credits
Thanks to Bob Remeika and David Waller for the [original code](https://github.com/foobarfighter/safe-migrations).