class MultitenancyTools::SchemaCreator

{SchemaCreator} can be used to create a schema on a PostgreSQL database using a SQL file as template. This template should be previously generated by {SchemaDumper}.

@example

creator = MultitenancyTools::SchemaCreator.new('schema name', ActiveRecord::Base.connection)
creator.create_from_file('path/to/file.sql')

Public Class Methods

new(schema, connection = ActiveRecord::Base.connection) click to toggle source

@param schema [String] schema name @param connection [ActiveRecord::ConnectionAdapters::PostgreSQLAdapter] connection adapter

# File lib/multitenancy_tools/schema_creator.rb, line 12
def initialize(schema, connection = ActiveRecord::Base.connection)
  @schema = schema
  @connection = connection
end

Public Instance Methods

create_from_file(file) click to toggle source

Creates the schema using a SQL file that was generated by {SchemaDumper}.

@param file [String] path to a SQL file

# File lib/multitenancy_tools/schema_creator.rb, line 20
def create_from_file(file)
  quoted_schema_name = @connection.quote_table_name(@schema)

  SchemaSwitcher.new(@schema, @connection).run do
    @connection.create_schema(quoted_schema_name)
    @connection.execute(File.read(file))
  end
end