Share Repo between umbrella apps

This is my first time with umbrella apps. I have created two apps. app1 and app2 and add app2 in app1 as an umbrella dependency. I don’t want to have separate data base for app1. I want to share the app2 repo between them.
How to configure it?

Thanks

1 Like

You can create a database app and share this between app1 and app2.

defp deps do
  [
    {:phoenix, "~> 1.3.2"},
    {:phoenix_pubsub, "~> 1.0"},
    {:phoenix_ecto, "~> 3.2"},
    {:phoenix_html, "~> 2.10"},
    {:phoenix_live_reload, "~> 1.0", only: :dev},
    {:gettext, "~> 0.11"},
    {:cowboy, "~> 1.0"},

    {:database, in_umbrella: true}
  ]
end
3 Likes

I thought as it is a umbrella app so may be we can use the same repo by doing something like shared configuration or some thing like that

To expand on what @alexandrubagu was pointing you at, try this out and explore the generated code:

mix phx.new umbrella_test --umbrella

You’ll see in the apps/umbrella_test_web/mix.exs file that it references its sibling in the dependencies, as @alexandrubagu mentioned:

# Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.3.4"},
      {:phoenix_pubsub, "~> 1.0"},
      {:phoenix_ecto, "~> 3.2"},
      {:phoenix_html, "~> 2.10"},
      {:phoenix_live_reload, "~> 1.0", only: :dev},
      {:gettext, "~> 0.11"},
      {:umbrella_test, in_umbrella: true},
      {:cowboy, "~> 1.0"}
    ]
  end

If you were to then cd into apps/umbrella_test_web and run mix phx.gen.context Accounts User users name:string you’ll see some additional content generated in
both of the two umbrella apps, demonstrating the direct way you can reference and call code from the sibling app.

The Phoenix Contexts content may slightly obscure the behavior, but the TL;DR is that once the Repo is “in scope” via your in_umbrella: true, you can call the Repo module as normal from its sibling app. You’ll just need to be thoughtful about where you add new code, which Contexts tries to give some guard rails for if you happen to be working with Phoenix.

3 Likes