Module: MultitenancyTools
- Defined in:
- lib/multitenancy_tools.rb,
lib/multitenancy_tools/errors.rb,
lib/multitenancy_tools/version.rb,
lib/multitenancy_tools/dump_cleaner.rb,
lib/multitenancy_tools/table_dumper.rb,
lib/multitenancy_tools/schema_dumper.rb,
lib/multitenancy_tools/schema_creator.rb,
lib/multitenancy_tools/schema_switcher.rb,
lib/multitenancy_tools/functions_dumper.rb,
lib/multitenancy_tools/schema_destroyer.rb
Defined Under Namespace
Classes: DumpCleaner, FunctionsDumper, PgDumpError, SchemaCreator, SchemaDestroyer, SchemaDumper, SchemaSwitcher, TableDumper
Constant Summary collapse
- VERSION =
'0.1.10'
Class Method Summary collapse
-
.create(name, sql_file, connection = ActiveRecord::Base.connection) ⇒ Object
Creates a new schema using the SQL file as template.
-
.destroy(name, connection = ActiveRecord::Base.connection) ⇒ Object
Drops the schema from the database.
-
.dump_schema(database, schema, file, **args) ⇒ Object
Generates a SQL dump of the schema.
-
.dump_table(database, schema, table, file, **args) ⇒ Object
Generates a SQL dump of the table.
-
.using(schema, connection = ActiveRecord::Base.connection) { ... } ⇒ Object
Uses the passed schema as the scope for all queries triggered by the block.
Class Method Details
.create(name, sql_file, connection = ActiveRecord::Base.connection) ⇒ Object
Creates a new schema using the SQL file as template. This SQL file can be generated by SchemaDumper.
20 21 22 |
# File 'lib/multitenancy_tools.rb', line 20 def self.create(name, sql_file, connection = ActiveRecord::Base.connection) SchemaCreator.new(name, connection).create_from_file(sql_file) end |
.destroy(name, connection = ActiveRecord::Base.connection) ⇒ Object
Drops the schema from the database.
29 30 31 |
# File 'lib/multitenancy_tools.rb', line 29 def self.destroy(name, connection = ActiveRecord::Base.connection) SchemaDestroyer.new(name, connection).destroy end |
.dump_schema(database, schema, file, **args) ⇒ Object
Generates a SQL dump of the schema. Requires pg_dump.
49 50 51 |
# File 'lib/multitenancy_tools.rb', line 49 def self.dump_schema(database, schema, file, **args) SchemaDumper.new(database, schema).dump_to(file, **args) end |
.dump_table(database, schema, table, file, **args) ⇒ Object
Generates a SQL dump of the table. Requires pg_dump.
60 61 62 |
# File 'lib/multitenancy_tools.rb', line 60 def self.dump_table(database, schema, table, file, **args) TableDumper.new(database, schema, table).dump_to(file, **args) end |
.using(schema, connection = ActiveRecord::Base.connection) { ... } ⇒ Object
Uses the passed schema as the scope for all queries triggered by the block.
39 40 41 |
# File 'lib/multitenancy_tools.rb', line 39 def self.using(schema, connection = ActiveRecord::Base.connection, &block) SchemaSwitcher.new(schema, connection).run(&block) end |