Module: SafePgMigrations::StatementInsurer
Defined Under Namespace
Modules: AddColumn, ChangeColumnNull, RemoveColumnIndex
Instance Method Summary
collapse
-
#add_check_constraint(table_name, expression, **options) ⇒ Object
-
#add_foreign_key(from_table, to_table, **options) ⇒ Object
-
#add_index(table_name, column_name, **options) ⇒ Object
-
#create_table(table_name, **options) ⇒ Object
-
#drop_table(table_name, **options) ⇒ Object
-
#remove_column(table_name, column_name, type = nil, **options) ⇒ Object
-
#remove_index(table_name, column_name = nil, **options) ⇒ Object
-
#validate_check_constraint(table_name, **options) ⇒ Object
-
#validate_foreign_key ⇒ Object
#remove_column_with_composite_index
#change_column_null
Methods included from AddColumn
#add_column
#with_setting, #without_lock_timeout, #without_statement_timeout, #without_timeout
Instance Method Details
#add_check_constraint(table_name, expression, **options) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/safe-pg-migrations/plugins/statement_insurer.rb', line 15
def add_check_constraint(table_name, expression, **options)
Helpers::SatisfiedHelper.satisfies_add_check_constraints!
return unless supports_check_constraints?
options = check_constraint_options(table_name, expression, options)
Helpers::Logger.say_method_call :add_check_constraint, table_name, expression, **options,
validate: false
super(table_name, expression, **options, validate: false)
return unless options.fetch(:validate, true)
validate_check_constraint table_name, name: options[:name]
end
|
#add_foreign_key(from_table, to_table, **options) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/safe-pg-migrations/plugins/statement_insurer.rb', line 34
def add_foreign_key(from_table, to_table, **options)
validate_present = options.key?(:validate)
options[:validate] = false unless validate_present
super(from_table, to_table, **options)
return if validate_present
sub_options = options.slice(:name, :column)
validate_foreign_key from_table, sub_options.present? ? nil : to_table, **sub_options
end
|
#add_index(table_name, column_name, **options) ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/safe-pg-migrations/plugins/statement_insurer.rb', line 56
def add_index(table_name, column_name, **options)
if options[:algorithm] == :default
options.delete :algorithm
else
options[:algorithm] = :concurrently
end
Helpers::Logger.say_method_call(:add_index, table_name, column_name, **options)
without_timeout { super(table_name, column_name, **options) }
end
|
#create_table(table_name, **options) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/safe-pg-migrations/plugins/statement_insurer.rb', line 46
def create_table(table_name, **options)
super do |td|
yield td if block_given?
td.indexes.map! do |key, index_options|
index_options[:algorithm] ||= :default
[key, index_options]
end
end
end
|
#drop_table(table_name, **options) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/safe-pg-migrations/plugins/statement_insurer.rb', line 82
def drop_table(table_name, **options)
foreign_keys(table_name).each do |foreign_key|
remove_foreign_key(table_name, name: foreign_key.name)
end
Helpers::Logger.say_method_call :drop_table, table_name, **options
super
end
|
#remove_column(table_name, column_name, type = nil, **options) ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/safe-pg-migrations/plugins/statement_insurer.rb', line 74
def remove_column(table_name, column_name, type = nil, **options)
foreign_key = foreign_key_for(table_name, column: column_name)
remove_foreign_key(table_name, name: foreign_key.name) if foreign_key
remove_column_with_composite_index(table_name, column_name)
super
end
|
#remove_index(table_name, column_name = nil, **options) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/safe-pg-migrations/plugins/statement_insurer.rb', line 67
def remove_index(table_name, column_name = nil, **options)
options[:algorithm] = :concurrently unless options.key?(:algorithm)
Helpers::Logger.say_method_call(:remove_index, table_name, column_name, **options)
without_timeout { super(table_name, column_name, **options) }
end
|
#validate_check_constraint(table_name, **options) ⇒ Object
10
11
12
13
|
# File 'lib/safe-pg-migrations/plugins/statement_insurer.rb', line 10
def validate_check_constraint(table_name, **options)
Helpers::Logger.say_method_call :validate_check_constraint, table_name, **options
without_statement_timeout { super }
end
|
#validate_foreign_key ⇒ Object
30
31
32
|
# File 'lib/safe-pg-migrations/plugins/statement_insurer.rb', line 30
def validate_foreign_key(*, **)
without_statement_timeout { super }
end
|