Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support loading resources from replica database with Rails 6.1 multi-database feature #868

Open
sunnybogawat opened this issue Sep 19, 2024 · 0 comments

Comments

@sunnybogawat
Copy link

Feature Request: Support loading resources from replica database with Rails 6.1 multi-database feature

Background:
Rails 6.1 introduced native support for multiple databases, including primary and replica databases configuration. This feature allows read and write operations to be directed to different databases, making it easier to scale applications by distributing the load.

Request:
I would like to request a feature in CanCanCan to support loading resources from the replica database. Currently, while it is possible to load resources using the load_and_authorize_resource method, there is no straightforward way to direct these read operations to a replica database.

Use Case:
Using the replica database for read-heavy operations such as listing resources or fetching details of a particular resource can enhance performance and reliability. To integrate CanCanCan with the new multi-database feature of Rails 6.1, it would be highly beneficial if the gem provided native support or a configuration mechanism to specify the database from which to load resources.

Suggested Implementation:

  1. Allow an option or flag within the load_and_authorize_resource method to specify which database to use.
  2. Integrate with Rails' connected_to framework to seamlessly switch the connection for specific actions.

Example:

class BooksController < ApplicationController
  load_and_authorize_resource from: :replica, only: [:index, :show]

  def index
    @books = Book.all
  end

  def show
    @book = Book.find(params[:id])
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant