Class: Apartment::Adapters::Mysql2Adapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- Apartment::Adapters::Mysql2Adapter
- Defined in:
- lib/apartment/adapters/mysql2_adapter.rb
Overview
v4 MySQL adapter using database-per-tenant isolation (mysql2 driver).
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.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from AbstractAdapter
Instance Method Summary collapse
-
#failsafe_error_classes ⇒ Object
The database-per-tenant missing-tenant error: connecting to a dropped database raises ActiveRecord::NoDatabaseError (MySQL error 1049) — an unambiguous signal.
-
#pinned_table_qualifier ⇒ Object
Pinned tables live in the default tenant's database; every tenant connection can reach them by database-qualifying the name.
- #resolve_connection_config(tenant, base_config: nil) ⇒ Object
- #shared_pinned_connection? ⇒ Boolean
Methods inherited from AbstractAdapter
#aborted_transaction?, #apply_pinned_qualification, #check_pinned_subclass, #create, #default_tenant, #drop, #environmentify, #inherits_pinned_table?, #initialize, #migrate, #nearest_pinned_ancestor, #physical_tenant_name, #process_excluded_models, #process_pinned_model, #process_pinned_models, #qualify_pinned_table_name, #qualify_pinned_table_name_prefix, #seed, #tenant_container_gone?, #unregistered_pinned_subclass?, #validated_connection_config, #warn_unqualified_subclass, #warn_unregistered_pinned_subclasses
Constructor Details
This class inherits a constructor from Apartment::Adapters::AbstractAdapter
Instance Method Details
#failsafe_error_classes ⇒ Object
The database-per-tenant missing-tenant error: connecting to a dropped database raises ActiveRecord::NoDatabaseError (MySQL error 1049) — an unambiguous signal. 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. Inherited by TrilogyAdapter.
34 35 36 |
# File 'lib/apartment/adapters/mysql2_adapter.rb', line 34 def failsafe_error_classes [ActiveRecord::NoDatabaseError, Apartment::ApartmentError] end |
#pinned_table_qualifier ⇒ Object
Pinned tables live in the default tenant's database; every tenant connection can reach them by database-qualifying the name.
19 20 21 |
# File 'lib/apartment/adapters/mysql2_adapter.rb', line 19 def pinned_table_qualifier base_config['database'] end |
#resolve_connection_config(tenant, base_config: nil) ⇒ Object
23 24 25 26 |
# File 'lib/apartment/adapters/mysql2_adapter.rb', line 23 def resolve_connection_config(tenant, base_config: nil) config = base_config || send(:base_config) config.merge('database' => environmentify(tenant)) end |