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

Multiple databases support #14

Open
wata727 opened this issue Jan 23, 2023 · 0 comments
Open

Multiple databases support #14

wata727 opened this issue Jan 23, 2023 · 0 comments

Comments

@wata727
Copy link
Collaborator

wata727 commented Jan 23, 2023

See also #12
See also #13

Currently this gem doesn't support multiple databases and you have to explicitly call TenantLevelSecurity.switch! when connecting other databases. But this is obviously inconvenient in read replicas.

One possible solution is that TenantLevelSecurity.switch! switches all connections on the current thread. This can be implemented by referring to AcitveRecord::Base.clear_query_caches_for_current_thread. See also rails/rails#35089
Note that some versions have different ways of getting the connection pool.

Another solution is to add a hook that fires when connecting to another database and run TenantLevelSecurity.switch! there. This is close to the current design of switching tenants using checkout callbacks, but I'm not sure if the same way works for multiple databases.

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