Module: StrongMigrations::Migration
- Defined in:
- lib/strong_migrations/migration.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/strong_migrations/migration.rb', line 16
def method_missing(method, *args, &block)
unless @safe || ENV["SAFETY_ASSURED"] || is_a?(ActiveRecord::Schema) || @direction == :down
case method
when :remove_column
raise_error :remove_column
when :remove_timestamps
raise_error :remove_column
when :change_table
raise_error :change_table
when :rename_table
raise_error :rename_table
when :rename_column
raise_error :rename_column
when :add_index
columns = args[1]
if columns.is_a?(Array) && columns.size > 3
raise_error :add_index_columns
end
options = args[2]
if %w(PostgreSQL PostGIS).include?(connection.adapter_name) && !(options && options[:algorithm] == :concurrently)
raise_error :add_index
end
when :add_column
type = args[2]
options = args[3]
raise_error :add_column_default if options && !options[:default].nil?
raise_error :add_column_json if type.to_s == "json"
when :change_column
raise_error :change_column
end
end
super
end
|
Instance Method Details
#migrate(direction) ⇒ Object
11
12
13
14
|
# File 'lib/strong_migrations/migration.rb', line 11
def migrate(direction)
@direction = direction
super
end
|
#safety_assured ⇒ Object
3
4
5
6
7
8
9
|
# File 'lib/strong_migrations/migration.rb', line 3
def safety_assured
previous_value = @safe
@safe = true
yield
ensure
@safe = previous_value
end
|