module MultitenancyTools
Constants
- VERSION
Public Class Methods
Creates a new schema using the SQL file as template. This SQL file can be generated by {SchemaDumper}.
@see SchemaCreator
@see SchemaDumper
@param name [String] schema name @param sql_file [String] absolute path to the SQL template @param connection [ActiveRecord::ConnectionAdapters::PostgreSQLAdapter] connection adapter
# File lib/multitenancy_tools.rb, line 24 def self.create(name, sql_file, connection = ActiveRecord::Base.connection) SchemaCreator.new(name, connection).create_from_file(sql_file) end
Drops the schema from the database.
@see SchemaDestroyer
@param name [String] schema name @param connection [ActiveRecord::ConnectionAdapters::PostgreSQLAdapter] connection adapter
# File lib/multitenancy_tools.rb, line 33 def self.destroy(name, connection = ActiveRecord::Base.connection) SchemaDestroyer.new(name, connection).destroy end
Generates a SQL dump of all extensions enabled on the database.
@see ExtensionsDumper
@param file [String] @param connection [ActiveRecord::ConnectionAdapters::PostgreSQLAdapter] connection adapter
# File lib/multitenancy_tools.rb, line 73 def self.dump_extensions(file, connection = ActiveRecord::Base.connection, **args) ExtensionsDumper.new(connection).dump_to(file, **args) end
Generates a SQL dump of the schema. Requires pg_dump.
@see SchemaDumper
@param database [String] @param schema [String] @param file [String]
# File lib/multitenancy_tools.rb, line 53 def self.dump_schema(database, schema, file, **args) SchemaDumper.new(database, schema).dump_to(file, **args) end
Generates a SQL dump of the table. Requires pg_dump.
@see TableDumper
@param database [String] @param schema [String] @param table [String] @param file [String]
# File lib/multitenancy_tools.rb, line 64 def self.dump_table(database, schema, table, file, **args) TableDumper.new(database, schema, table).dump_to(file, **args) end
Uses the passed schema as the scope for all queries triggered by the block.
@see SchemaSwitcher
@param schema [String] schema name @param connection [ActiveRecord::ConnectionAdapters::PostgreSQLAdapter] connection adapter @yield The block that must be executed using the schema as scope
# File lib/multitenancy_tools.rb, line 43 def self.using(schema, connection = ActiveRecord::Base.connection, &block) SchemaSwitcher.new(schema, connection).run(&block) end