class ZeroDowntimeMigrations::Validation::MixedMigration

Public Instance Methods

validate!() click to toggle source
  # File lib/zero_downtime_migrations/validation/mixed_migration.rb
4 def validate!
5   return unless Migration.mixed?
6   error!(message)
7 end

Private Instance Methods

message() click to toggle source
   # File lib/zero_downtime_migrations/validation/mixed_migration.rb
11       def message
12         <<-MESSAGE.strip_heredoc
13           Mixing data/index/schema changes in the same migration is unsafe!
14 
15           Instead, let's split apart these types of migrations into separate files.
16 
17           * Introduce schema changes with methods like `create_table` or `add_column`
18             in one file. These should be run within a DDL transaction so that they
19             can be rolled back if there are any issues.
20 
21           * Update data with methods like `update_all` or `save` in another file.
22             Data migrations tend to be much more error prone than changing the
23             schema or adding indexes.
24 
25           * Add indexes concurrently within their own file as well. Indexes should
26             be created without the DDL transaction enabled to avoid table locking.
27 
28           If you're 100% positive that this migration is already safe, then simply
29           add a call to `safety_assured` to your migration.
30 
31             class #{migration_name} < ActiveRecord::Migration
32               safety_assured
33 
34               def change
35                 # ...
36               end
37             end
38         MESSAGE
39       end