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_migrator.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, SchemaMigrator, SchemaSwitcher, TableDumper

Constant Summary collapse

VERSION =
'0.1.11'

Class Method Summary collapse

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.

Parameters:

  • name (String)

    schema name

  • sql_file (String)

    absolute path to the SQL template

  • connection (ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) (defaults to: ActiveRecord::Base.connection)

    connection adapter

See Also:



21
22
23
# File 'lib/multitenancy_tools.rb', line 21

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.

Parameters:

  • name (String)

    schema name

  • connection (ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) (defaults to: ActiveRecord::Base.connection)

    connection adapter

See Also:



30
31
32
# File 'lib/multitenancy_tools.rb', line 30

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.

Parameters:

  • database (String)
  • schema (String)
  • file (String)

See Also:



50
51
52
# File 'lib/multitenancy_tools.rb', line 50

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.

Parameters:

  • database (String)
  • schema (String)
  • table (String)
  • file (String)

See Also:



61
62
63
# File 'lib/multitenancy_tools.rb', line 61

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.

Parameters:

  • schema (String)

    schema name

  • connection (ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) (defaults to: ActiveRecord::Base.connection)

    connection adapter

Yields:

  • The block that must be executed using the schema as scope

See Also:



40
41
42
# File 'lib/multitenancy_tools.rb', line 40

def self.using(schema, connection = ActiveRecord::Base.connection, &block)
  SchemaSwitcher.new(schema, connection).run(&block)
end