Class: PGTrunk::Operations::Domains::ChangeDomain
- Inherits:
-
Base
show all
- Defined in:
- lib/pg_trunk/operations/domains/change_domain.rb
Instance Method Summary
collapse
Methods inherited from Base
#constraint
#quote
#dump, #to_a, #to_opts, #to_ruby
#invert!, #irreversible!
#error_messages
#attributes, #initialize
Instance Method Details
#add_constraint(check, name: nil, valid: true) ⇒ Object
Methods to populate constraints
from the block
62
63
64
|
# File 'lib/pg_trunk/operations/domains/change_domain.rb', line 62
def add_constraint(check, name: nil, valid: true)
constraints << Constraint.new(name: name, check: check, valid: valid)
end
|
#drop_constraint(name, check: nil, if_exists: nil) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/pg_trunk/operations/domains/change_domain.rb', line 74
def drop_constraint(name, check: nil, if_exists: nil)
constraints << Constraint.new(
check: check,
drop: true,
force: force,
if_exists: if_exists,
name: name,
)
end
|
#invert ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/pg_trunk/operations/domains/change_domain.rb', line 92
def invert
keys = inversion.select { |_, v| v.nil? }.keys.join(", ").presence
errors = constraints.map(&:inversion_error).compact
errors << "Can't invert #{keys}" if keys.present?
raise IrreversibleMigration.new(self, nil, *errors) if errors.any?
self.class.new(**to_h, **inversion)
end
|
#rename_constraint(name, to:) ⇒ Object
66
67
68
|
# File 'lib/pg_trunk/operations/domains/change_domain.rb', line 66
def rename_constraint(name, to:)
constraints << Constraint.new(name: name, new_name: to)
end
|
#to_sql(_version) ⇒ Object
87
88
89
90
|
# File 'lib/pg_trunk/operations/domains/change_domain.rb', line 87
def to_sql(_version)
[*change_default, *change_null, *change_constraints, *]
.join(" ")
end
|
#validate_constraint(name) ⇒ Object
70
71
72
|
# File 'lib/pg_trunk/operations/domains/change_domain.rb', line 70
def validate_constraint(name)
constraints << Constraint.new(name: name, valid: true)
end
|