Class: Apartment::Adapters::PostgresqlDatabaseAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- Apartment::Adapters::PostgresqlDatabaseAdapter
- Includes:
- PostgresqlTransactionState
- 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
Instance Method Summary collapse
-
#current_db_role(connection) ⇒ Object
The engine is the same as the schema strategy's, so the token is identical.
-
#failsafe_error_classes ⇒ Object
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.
- #resolve_connection_config(tenant, base_config: nil) ⇒ Object
Methods included from PostgresqlTransactionState
Methods inherited from AbstractAdapter
#aborted_transaction?, #apply_pinned_qualification, #awaiting_own_qualification?, #check_pinned_subclass, #create, #default_tenant, #drop, #environmentify, #inheriting_descendants, #inherits_pinned_table?, #initialize, #migrate, #nearest_pinned_ancestor, #physical_tenant_name, #pinned_qualification_mutates?, #pinned_table_name_for, #pinned_table_qualifier, #process_excluded_models, #process_pinned_model, #process_pinned_models, #qualify_pinned_table_name, #qualify_pinned_table_name_prefix, #seed, #shared_pinned_connection?, #standard_privilege_statements, #tenant_container_gone?, #unqualified_pinned_message, #unregistered_pinned_subclass?, #validated_connection_config, #verified_pinned_qualifier, #verify_pinned_qualification!, #warn_unqualified_descendants, #warn_unqualified_subclass, #warn_unregistered_pinned_subclasses
Constructor Details
This class inherits a constructor from Apartment::Adapters::AbstractAdapter
Instance Method Details
#current_db_role(connection) ⇒ Object
The engine is the same as the schema strategy's, so the token is identical. Implemented rather than inherited because this is the strategy most likely to need it: standard_privilege_statements raises here (see below), so privileges come from a hand-written policy, and that policy is exactly the code that wants ALTER DEFAULT PRIVILEGES FOR ROLE. Inheriting the base nil would leave it resolving the grantor itself, which is correct-by-position — the coupling this design removes.
37 38 39 |
# File 'lib/apartment/adapters/postgresql_database_adapter.rb', line 37 def current_db_role(connection) connection.select_value('SELECT current_user') end |
#failsafe_error_classes ⇒ Object
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.
26 27 28 |
# File 'lib/apartment/adapters/postgresql_database_adapter.rb', line 26 def failsafe_error_classes [ActiveRecord::NoDatabaseError, Apartment::ApartmentError] end |
#resolve_connection_config(tenant, base_config: nil) ⇒ Object
15 16 17 18 |
# File 'lib/apartment/adapters/postgresql_database_adapter.rb', line 15 def resolve_connection_config(tenant, base_config: nil) config = base_config || send(:base_config) config.merge('database' => environmentify(tenant)) end |