Class: MultitenancyTools::FunctionsDumper
- Inherits:
-
Object
- Object
- MultitenancyTools::FunctionsDumper
- Defined in:
- lib/multitenancy_tools/functions_dumper.rb
Overview
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.
Constant Summary collapse
- FUNCTIONS_SQL =
<<-SQL.freeze SELECT trim(trailing e' \n' from pg_get_functiondef(f.oid)) || ';' AS definition FROM pg_catalog.pg_proc f JOIN pg_catalog.pg_namespace n ON (f.pronamespace = n.oid) JOIN pg_catalog.pg_language l ON (f.prolang = l.oid) WHERE n.nspname = %s AND l.lanname != 'c'; SQL
Instance Method Summary collapse
-
#dump_to(file, mode: 'w') ⇒ Object
Generates a dump and writes it into a file.
-
#initialize(schema, connection = ActiveRecord::Base.connection) ⇒ FunctionsDumper
constructor
A new instance of FunctionsDumper.
Constructor Details
#initialize(schema, connection = ActiveRecord::Base.connection) ⇒ FunctionsDumper
Returns a new instance of FunctionsDumper.
24 25 26 27 |
# File 'lib/multitenancy_tools/functions_dumper.rb', line 24 def initialize(schema, connection = ActiveRecord::Base.connection) @connection = connection @schema = @connection.quote(schema) end |
Instance Method Details
#dump_to(file, mode: 'w') ⇒ Object
Generates a dump and writes it into a file. Please see IO.new for open modes.
36 37 38 39 40 41 42 43 44 |
# 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 |