module ZeroDowntimeMigrations::Migration

Public Class Methods

new(*) click to toggle source
Calls superclass method
   # File lib/zero_downtime_migrations/migration.rb
 9 def initialize(*)
10   ActiveRecord::Base.send(:prepend, Data)
11   ActiveRecord::Relation.send(:prepend, Relation)
12   super
13 end
prepended(mod) click to toggle source
  # File lib/zero_downtime_migrations/migration.rb
5 def self.prepended(mod)
6   mod.singleton_class.prepend(DSL)
7 end

Public Instance Methods

ddl_disabled?() click to toggle source
   # File lib/zero_downtime_migrations/migration.rb
15 def ddl_disabled?
16   !!disable_ddl_transaction
17 end
define(*) click to toggle source
Calls superclass method
   # File lib/zero_downtime_migrations/migration.rb
19 def define(*)
20   Migration.current = self
21   Migration.safe = true
22   super.tap { Migration.current = nil }
23 end
migrate(direction) click to toggle source
Calls superclass method
   # File lib/zero_downtime_migrations/migration.rb
25 def migrate(direction)
26   @direction = direction
27 
28   Migration.current = self
29   Migration.data = false
30   Migration.ddl = false
31   Migration.index = false
32   Migration.safe ||= reverse_migration? || rollup_migration?
33 
34   super.tap do
35     validate(:ddl_migration)
36     validate(:mixed_migration)
37     Migration.current = nil
38     Migration.safe = false
39   end
40 end

Private Instance Methods

ddl_method?(method) click to toggle source
   # File lib/zero_downtime_migrations/migration.rb
44 def ddl_method?(method)
45   %i(
46     add_belongs_to
47     add_column
48     add_foreign_key
49     add_reference
50     add_timestamps
51     change_column
52     change_column_default
53     change_column_null
54     change_table
55     create_join_table
56     create_table
57     drop_join_table
58     drop_table
59     remove_belongs_to
60     remove_column
61     remove_columns
62     remove_foreign_key
63     remove_index
64     remove_index!
65     remove_reference
66     remove_timestamps
67     rename_column
68     rename_column_indexes
69     rename_index
70     rename_table
71     rename_table_indexes
72   ).include?(method)
73 end
index_method?(method) click to toggle source
   # File lib/zero_downtime_migrations/migration.rb
75 def index_method?(method)
76   %i(add_index).include?(method)
77 end
method_missing(method, *args) click to toggle source
Calls superclass method
   # File lib/zero_downtime_migrations/migration.rb
79 def method_missing(method, *args)
80   Migration.ddl = true if ddl_method?(method)
81   Migration.index = true if index_method?(method)
82   validate(method, *args)
83   super
84 end
reverse_migration?() click to toggle source
   # File lib/zero_downtime_migrations/migration.rb
86 def reverse_migration?
87   @direction == :down
88 end
rollup_migration?() click to toggle source
   # File lib/zero_downtime_migrations/migration.rb
90 def rollup_migration?
91   self.class.name == "RollupMigrations"
92 end
safety_assured() { || ... } click to toggle source
    # File lib/zero_downtime_migrations/migration.rb
 94 def safety_assured
 95   safe = Migration.safe
 96   Migration.safe = true
 97   yield
 98 ensure
 99   Migration.safe = safe
100 end
validate(type, *args) click to toggle source
    # File lib/zero_downtime_migrations/migration.rb
102 def validate(type, *args)
103   Validation.validate!(type, *args)
104 rescue UndefinedValidationError
105   nil
106 end