Class: MultitenancyTools::SchemaCreator
- Inherits:
-
Object
- Object
- MultitenancyTools::SchemaCreator
- Defined in:
- lib/multitenancy_tools/schema_creator.rb
Overview
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.
Instance Method Summary collapse
-
#create_from_file(file) ⇒ Object
Creates the schema using a SQL file that was generated by SchemaDumper.
-
#initialize(schema, connection = ActiveRecord::Base.connection) ⇒ SchemaCreator
constructor
A new instance of SchemaCreator.
Constructor Details
#initialize(schema, connection = ActiveRecord::Base.connection) ⇒ SchemaCreator
Returns a new instance of SchemaCreator.
12 13 14 15 |
# File 'lib/multitenancy_tools/schema_creator.rb', line 12 def initialize(schema, connection = ActiveRecord::Base.connection) @schema = schema @connection = connection end |
Instance Method Details
#create_from_file(file) ⇒ Object
Creates the schema using a SQL file that was generated by MultitenancyTools::SchemaDumper.
20 21 22 23 24 25 26 27 |
# 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 |