class MultitenancyTools::ExtensionsDumper
{ExtensionsDumper} can be used to generate a SQL dump of all extensions that are enabled on a PostgreSQL database.
@example
dumper = MultitenancyTools::ExtensionsDumper.new dumper.dump_to('path/to/file.sql')
Constants
- CREATE_EXTENSION_SQL
- EXTENSION_SQL
Public Class Methods
new(connection = ActiveRecord::Base.connection)
click to toggle source
@param connection [ActiveRecord::ConnectionAdapters::PostgreSQLAdapter] connection adapter
# File lib/multitenancy_tools/extensions_dumper.rb, line 17 def initialize(connection = ActiveRecord::Base.connection) @connection = connection 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/extensions_dumper.rb, line 28 def dump_to(file, mode: 'w') results = @connection.execute(EXTENSION_SQL) File.open(file, mode) do |f| results.each do |result| name = result.fetch('extname') schema = result.fetch('nspname') f.puts(format(CREATE_EXTENSION_SQL, name, schema)) end end end