Class: Apartment::Adapters::PostgresqlSchemaAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/apartment/adapters/postgresql_schema_adapter.rb

Overview

v4 PostgreSQL adapter using schema-based tenant isolation.

Resolves tenant-specific connection configs by setting ‘schema_search_path` to the raw tenant name (not environmentified — schemas are named directly, unlike database-per-tenant adapters) plus any persistent schemas from Apartment.config.postgres_config. Lifecycle operations (create/drop) execute DDL against the default connection.

Instance Attribute Summary

Attributes inherited from AbstractAdapter

#connection_config

Instance Method Summary collapse

Methods inherited from AbstractAdapter

#create, #default_tenant, #drop, #environmentify, #initialize, #migrate, #process_excluded_models, #process_pinned_model, #process_pinned_models, #seed, #validated_connection_config

Constructor Details

This class inherits a constructor from Apartment::Adapters::AbstractAdapter

Instance Method Details

#resolve_connection_config(tenant, base_config: nil) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/apartment/adapters/postgresql_schema_adapter.rb', line 15

def resolve_connection_config(tenant, base_config: nil)
  config = base_config || send(:base_config)
  persistent = Apartment.config.postgres_config&.persistent_schemas || []
  search_path = [tenant, *persistent].join(',')

  config.merge('schema_search_path' => search_path)
end