Class: MultitenancyTools::SchemaDumper
- Inherits:
-
Object
- Object
- MultitenancyTools::SchemaDumper
- Defined in:
- lib/multitenancy_tools/schema_dumper.rb
Overview
SchemaDumper can be used to generate SQL dumps of the structure of a PostgreSQL schema. It requires pg_dump.
The generated dump DOES NOT contain:
-
privilege statements (GRANT/REVOKE)
-
tablespace assigments
-
ownership information
-
any table data
-
extensions (CREATE EXTENSION)
SchemaDumper is suitable to create SQL templates for SchemaCreator.
Instance Method Summary collapse
-
#dump_to(file, mode: 'w') ⇒ Object
Generates a dump an writes it into a file.
-
#initialize(database, schema, options = {}) ⇒ SchemaDumper
constructor
A new instance of SchemaDumper.
Constructor Details
#initialize(database, schema, options = {}) ⇒ SchemaDumper
Returns a new instance of SchemaDumper.
24 25 26 27 28 29 |
# File 'lib/multitenancy_tools/schema_dumper.rb', line 24 def initialize(database, schema, = {}) @database = database @schema = schema @host = .fetch(:host, '') @username = .fetch(:username, '') end |
Instance Method Details
#dump_to(file, mode: 'w') ⇒ Object
Generates a dump an writes it into a file. Please see IO.new for open modes.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/multitenancy_tools/schema_dumper.rb', line 38 def dump_to(file, mode: 'w') stdout, stderr, status = Dump::SchemaOnly.new( schema: @schema, host: @host, username: @username, database: @database ).dump fail(PgDumpError, stderr) unless status.success? File.open(file, mode) do |f| f.write DumpCleaner.new(stdout, @schema).clean end end |