-
Notifications
You must be signed in to change notification settings - Fork 29
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
Alter the query instead of the repo #21
base: master
Are you sure you want to change the base?
Alter the query instead of the repo #21
Conversation
Disregard this comment, it's all now in the PR I would like to enforce the specification of a tenant, and raise an appropriate error if one is missing. To do this, I've created a repo that wraps the 'real' ecto repo. It will then check for the prefix and raise if it is missing. Other methods are then defdelegate-d to the repo. I'm not thrilled with how this looks. I figure there is probably a metaprogramming solution that will do this much more elegantly, and without me having to be so intimately tied to the stuff being generated by Ecto. But so far it's working.
In my case, all of the tables are in schemas except for the tenants themselves, so when I create a tenant, I pass in the 'real' Repo. But ideally, this could be configured in such a way that you could tell it which tables require tenants, and which do not. Thoughts/Suggestions? |
Disregard this comment, it's all now in the PR
once you can pass in the models that should and should not be tenanted, I think this entire thing can be simplified to just:
|
Wondering if we can just import Ecto.Repo, then do something like enumerating through info(:functions) to patch the functions with the guard. That or proxy module that checks the guard before passing function/arity direct to Ecto.Repo. I'm on a road trip, but will be back Monday to take a look :-) |
…here the model is tenanted
@Dania02525 I've got this sorted out, I think. No rush. Enjoy your road trip! |
…a different signature, to increase compatibility with other libraries
8c91ec6
to
bad33fe
Compare
Hi @Dania02525, have you had a chance to look into this at all? I tried the 'enumerating' option you were thinking first, but in the end I skipped it because:
|
I was just starting to work on a pull request to swap the repo and the queryable places because repo as first param blocks apartmentex api of being piped. But your solution do the job too. |
@danielfoxp2 - https://github.com/promptworks/tenantex is what I wound up with. |
I've been struggling w/ other libraries that are expecting an object with Ecto's standard method signatures. This strategy leaves the existing functionality untouched, but exposes the private helper methods in their own module so they can be pulled in separately.
A few points to note: