Class: Apartment::Adapters::PostgresqlDatabaseAdapter

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

Overview

v4 PostgreSQL adapter using database-per-tenant isolation.

Resolves tenant-specific connection configs by setting the ‘database` key to the environmentified tenant name. 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, #qualify_pinned_table_name, #seed, #shared_pinned_connection?, #tenant_container_gone?, #validated_connection_config

Constructor Details

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

Instance Method Details

#failsafe_error_classesObject

The database-per-tenant missing-tenant error: connecting to a dropped database raises ActiveRecord::NoDatabaseError (PG SQLSTATE 3D000) — an unambiguous signal, unlike the schema strategy’s 42P01. It surfaces raw at query time, or wrapped in ApartmentError when ConnectionHandling resolves the pool (the dev-mode pending-migration check), so both are listed; #container_error? gates on the unwrapped NoDatabaseError.



24
25
26
# File 'lib/apartment/adapters/postgresql_database_adapter.rb', line 24

def failsafe_error_classes
  [ActiveRecord::NoDatabaseError, Apartment::ApartmentError]
end

#resolve_connection_config(tenant, base_config: nil) ⇒ Object



13
14
15
16
# File 'lib/apartment/adapters/postgresql_database_adapter.rb', line 13

def resolve_connection_config(tenant, base_config: nil)
  config = base_config || send(:base_config)
  config.merge('database' => environmentify(tenant))
end