class MultitenancyTools::FunctionsDumper
{FunctionsDumper} can be used to generate a SQL dump of all functions that are present on a PostgreSQL schema.
Please note that C functions are not included in the dump.
@example
dumper = MultitenancyTools::FunctionsDumper.new('schema name') dumper.dump_to('path/to/file.sql')
Constants
- FUNCTIONS_SQL
Public Class Methods
new(schema, connection = ActiveRecord::Base.connection)
click to toggle source
@param schema [String] schema name @param connection [ActiveRecord::ConnectionAdapters::PostgreSQLAdapter] connection adapter
# File lib/multitenancy_tools/functions_dumper.rb, line 24 def initialize(schema, connection = ActiveRecord::Base.connection) @connection = connection @schema = @connection.quote(schema) end
Public Instance Methods
dump_to(file, mode: 'w')
click to toggle source
Generates a dump and writes it into a file. Please see {IO.new} for open modes.
@see ruby-doc.org/core-2.2.2/IO.html#method-c-new-label-Open+Mode
IO Open Modes
@param file [String] file path @param mode [String] IO open mode
# File lib/multitenancy_tools/functions_dumper.rb, line 36 def dump_to(file, mode: 'w') results = @connection.execute(format(FUNCTIONS_SQL, @schema)) File.open(file, mode) do |f| results.each do |result| f.puts result.fetch('definition') end end end