Multitenancy and Oban

Hi folks.

I have a web app running using foreign keys for multitenancy (see Multi tenancy with foreign keys).

Turns out Oban doesn’t play so nicely with this set up due to the prepare_query/3 function in the Repo module. I saw one issue related to this on Github (see Set flag in query options to detect oban query) but no solution.

I have managed to get Oban up and running by creating a second repo module with the same database configuration, except only for Oban.

Are there any drawbacks to using two repos in this way?

I encountered the exact same issue and chose a slightly different option. Instead of using a different repo, I chose to install Oban using its own table prefix, and then used that comparison to ignore the tenancy requirements in prepare_query:

unless opts[:prefix] == "private" do
  …
end

3 Likes

Ah, lovely! That’s a neater solution.