class PGTrunk::Operations::Functions::ChangeFunction
@private
Public Instance Methods
invert()
click to toggle source
# File lib/pg_trunk/operations/functions/change_function.rb, line 72 def invert irreversible!("if_exists: true") if if_exists undefined = inversion.select { |_, v| v.nil? }.keys.join(", ").presence raise IrreversibleMigration.new(self, nil, <<~MSG.squish) if undefined Undefined values to revert #{undefined}. MSG self.class.new(**inversion, name: name) end
to_sql(server_version)
click to toggle source
# File lib/pg_trunk/operations/functions/change_function.rb, line 67 def to_sql(server_version) # Use `CREATE OR REPLACE FUNCTION` to make changes create_function&.to_sql(server_version) end
Private Instance Methods
changes()
click to toggle source
# File lib/pg_trunk/operations/functions/change_function.rb, line 96 def changes @changes ||= to_h.except(:name).reject { |_, v| v.nil? || v == "" } end
create_function()
click to toggle source
# File lib/pg_trunk/operations/functions/change_function.rb, line 84 def create_function return if name.blank? @create_function ||= begin list = CreateFunction.select { |obj| name.maybe_eq?(obj.name) } list.select! { |obj| name == obj.name } if list.size > 1 && name.args list.first&.tap do |op| op.attributes = { **changes, replace_existing: true } end end end
inversion()
click to toggle source
# File lib/pg_trunk/operations/functions/change_function.rb, line 100 def inversion @inversion ||= { body: [body, from_body], volatility: [volatility, from_volatility], parallel: [parallel, from_parallel], cost: [cost, from_cost], rows: [rows, from_rows], comment: [comment, from_comment], security: [security, (security == :invoker ? :definer : :invoker)], leakproof: [leakproof, !leakproof], strict: [strict, !strict], }.slice(*changes.keys).transform_values(&:last) end