Sha256: 098803d45a373f2c952aaf42ab857aba7aeba3342c3d5b8af23944b4902c452f
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
# frozen_string_literal: false # @!parse # class ActiveRecord::Migration # # Change the name and/or schema of a procedure # # # # @param [#to_s] :name (nil) The qualified name of the procedure # # @option [#to_s] :to (nil) The new qualified name for the procedure # # @return [void] # # # # A procedure can be renamed by changing both the name # # and the schema (namespace) it belongs to. # # # # If there are no overloaded procedures, then you can use a plain name: # # # # rename_procedure "math.set_foo", to: "public.foo_setup" # # # # otherwise the types of attributes must be explicitly specified. # # # # rename_procedure "math.set_foo(int)", to: "public.foo_setup" # # # # Any specification of attributes in `to:` option # # is ignored because they cannot be changed anyway. # # # # The operation is always reversible. # def rename_procedure(name, to:); end # end module PGTrunk::Operations::Procedures # @private class RenameProcedure < Base validates :new_name, presence: true validates :body, :if_exists, :replace_existing, :language, :security, absence: true def to_sql(version) check_version!(version) [*change_schema, *change_name].join("; ") end def invert q_new_name = "#{new_name.schema}.#{new_name.routine}(#{name.args}) #{name.returns}" self.class.new(**to_h, name: q_new_name.strip, to: name) end private def change_schema return if name.schema == new_name.schema "ALTER PROCEDURE #{name.to_sql} SET SCHEMA #{new_name.schema.inspect};" end def change_name return if new_name.routine == name.routine changed_name = name.merge(schema: new_name.schema).to_sql "ALTER PROCEDURE #{changed_name} RENAME TO #{new_name.routine.inspect};" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pg_trunk-0.1.1 | lib/pg_trunk/operations/procedures/rename_procedure.rb |