lib/penthouse/tenants/schema_tenant.rb in penthouse-0.3.0 vs lib/penthouse/tenants/schema_tenant.rb in penthouse-0.4.0
- old
+ new
@@ -30,10 +30,11 @@
# switches to the tenant schema to run the block, ensuring we switch back
# afterwards, regardless of whether an exception occurs
# @param block [Block] The code to execute within the schema
# @yield [SchemaTenant] The current tenant instance
+ # @return [void]
def call(&block)
begin
# set the search path to include the tenant
ActiveRecord::Base.connection.schema_search_path = persistent_schemas.dup.unshift(tenant_schema).join(", ")
block.yield(self)
@@ -44,19 +45,21 @@
end
# creates the tenant schema
# @param run_migrations [Boolean] whether or not to run migrations, defaults to Penthouse.configuration.migrate_tenants?
# @param db_schema_file [String] a path to the DB schema file to load, defaults to Penthouse.configuration.db_schema_file
+ # @return [void]
def create(run_migrations: Penthouse.configuration.migrate_tenants?, db_schema_file: Penthouse.configuration.db_schema_file)
sql = ActiveRecord::Base.send(:sanitize_sql_array, ["create schema if not exists %s", tenant_schema])
ActiveRecord::Base.connection.exec_query(sql, 'Create Schema')
if !!run_migrations
migrate(db_schema_file: db_schema_file)
end
end
# drops the tenant schema
# @param force [Boolean] whether or not to drop the schema if not empty, defaults to true
+ # @return [void]
def delete(force: true)
sql = ActiveRecord::Base.send(:sanitize_sql_array, ["drop schema if exists %s %s", tenant_schema, force ? 'cascade' : 'restrict'])
ActiveRecord::Base.connection.exec_query(sql, 'Delete Schema')
end