phoenix_ecto icon indicating copy to clipboard operation
phoenix_ecto copied to clipboard

Phoenix.Ecto.SQL.Sandbox support for multi repos?

Open Cowa opened this issue 2 years ago • 2 comments

Hello! 👋

I'd like to use the sandbox plug with multi repos, like this:

plug(Phoenix.Ecto.SQL.Sandbox,
    at: "/sandbox",
    repo: [MyApp.Repo1, MyApp.Repo2],
    timeout: 60_000,
)

By reading the code source I found some hints that made me think it would be possible: https://github.com/phoenixframework/phoenix_ecto/blob/4d6b23c218f2cdca4f07b68e3dc67c4d87b6f5e3/lib/phoenix_ecto/sql/sandbox.ex#L250-L253

https://github.com/phoenixframework/phoenix_ecto/blob/4d6b23c218f2cdca4f07b68e3dc67c4d87b6f5e3/lib/phoenix_ecto/sql/sandbox.ex#L308-L309

But actually it's not working. If I understand correctly it's because here we start the SandboxSupervisor but it expects a single repo in its child_spec:

https://github.com/phoenixframework/phoenix_ecto/blob/4d6b23c218f2cdca4f07b68e3dc67c4d87b6f5e3/lib/phoenix_ecto/sql/sandbox.ex#L152-L155

I'm not familiar with all of this, but should we start a SandboxSupervisor for each repo?

I can try to make a fix if needed :)

Thanks!

Cowa avatar Jun 01 '22 09:06 Cowa

You are right. It seems we don't allow multiple repos on the Plug API. The fix is to change the SandboxSession to receive multiple repos and manage multiple repos at once. A PR is welcome.

josevalim avatar Jun 01 '22 10:06 josevalim

Thanks! I will work on that next week.

Cowa avatar Jun 01 '22 12:06 Cowa