Module: Doorkeeper::Models::Concerns::WriteToPrimary
- Extended by:
- ActiveSupport::Concern
- Included in:
- AccessGrantMixin, AccessTokenMixin
- Defined in:
- lib/doorkeeper/models/concerns/write_to_primary.rb
Overview
Provides support for Rails read replicas by ensuring write operations use the primary database when automatic role switching is enabled.
When Rails uses automatic role switching with read replicas, GET requests are routed to read-only databases. However, Doorkeeper may need to write to the database during GET requests (e.g., creating access tokens during implicit grant flow). This concern wraps write operations with ‘connected_to(role: :writing)` to ensure they use the primary database.
This concern is only active when:
-
ActiveRecord supports ‘connected_to` (Rails 6.1+)
-
The configuration option is enabled