class ZeroDowntimeMigrations::Validation::FindEach

Public Instance Methods

validate!() click to toggle source
  # File lib/zero_downtime_migrations/validation/find_each.rb
4 def validate!
5   error!(message)
6 end

Private Instance Methods

message() click to toggle source
   # File lib/zero_downtime_migrations/validation/find_each.rb
10       def message
11         <<-MESSAGE.strip_heredoc
12           Using `ActiveRecord::Relation#each` is unsafe!
13 
14           Let's use the `find_each` method to fetch records in batches instead.
15 
16           Otherwise we may accidentally load tens or hundreds of thousands of
17           records into memory all at the same time!
18 
19           If you're 100% positive that this migration is already safe, then wrap the
20           call to `each` in a `safety_assured` block.
21 
22             class #{migration_name} < ActiveRecord::Migration
23               def change
24                 safety_assured do
25                   # use ActiveRecord::Relation.each in this block
26                 end
27               end
28             end
29         MESSAGE
30       end