clemensm

clemensm

Using same Ecto Sandbox Connection for two Repos

Hi there

I’m currently developing a Phoenix App that acts as a view for two sub applications. I.e. the layout in terms of umbrella projects is something like this:

- apps
    - appA
    - appB
    - appPhoenix

appA and appB each have their own Repo, but appB is based on appA and writes to the same database (there are foreign key constraints in appB based on appA). appA itself is used across multiple projects.

Now I’d like to write some tests in appPhoenix where I test the json API it is offering to see if e.g. a POST request does what it is supposed to. For the test I’m using the Ecto Sandbox in shared mode, which is working fine as long as the request I’m sending does not require both Repo’s from appA and appB. The problem is obviously that I did check out a :shared connection for appB.Repo in the test setup, i.e.:

  setup tags do
    :ok = Ecto.Adapters.SQL.Sandbox.checkout(appB.Repo)

    unless tags[:async] do
      Ecto.Adapters.SQL.Sandbox.mode(appB.Repo, {:shared, self()})
    end

    :ok
  end

But obviously appA has it’s own repo and that one is not setup to use the same connection like appB.Repo.

My question now is: Is there a possibility to configure the appA.Repo to use the same shared connection that appB.Repo is using in the tests? So far I’ve not been able to setup such a configurtation, any help would be much appreciated.

First Post!

BartOtten

BartOtten

Like this?

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement