Facing compilation issue when integrating two apps

I have two separate applications for a web app I am building.

  1. Phoenix application ( which has UI ) - example_web
  2. Elixir application + ecto ( which has business logic ) - example

Based on the ideas mentioned in this post, I decided to keep the persistence and web layer in different applications.

However, I ran into an error when trying to start the example_web app after adding example app as a dependency in mix.exs file.

== Compilation error in file lib/example/repo.ex ==
** (ArgumentError) missing :adapter configuration in config :example, Example.Repo
    lib/ecto/repo/supervisor.ex:70: Ecto.Repo.Supervisor.compile_config/2
    lib/example/repo.ex:2: (module)
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6

example has database config information similar to https://github.com/wojtekmach/acme_bank/blob/master/apps/bank/config/dev.exs

# lib/example/repo.ex
defmodule Example.Repo do
  use Ecto.Repo, otp_app: :example
end

example_web has similar config to https://github.com/wojtekmach/acme_bank/tree/master/apps/bank_web/config

I am not able to figure out where I am going wrong. Your help is appreciated.

PS: I am not using umbrella app here.

Can you post configs for your repo?

> missing :adapter configuration in config :example, Example.Repo

indicates that you probably forgot to move repo configs from your “phoenix app”.

PS: I am not using umbrella app here.

What are you using then? Can you post your directory structure?

These are two separate folders

  • chart ( example_web )
    README.md _build/ assets/ config/ deps/ lib/ mix.exs mix.lock priv/ test/
  • example
    README.md _build/ config/ deps/ lib/ mix.exs mix.lock priv/ test/
## example_web
use Mix.Config

# Configures the endpoint
config :chart, ChartWeb.Endpoint,
  url: [host: "localhost"],
  secret_key_base: "abcd",
  render_errors: [view: ChartWeb.ErrorView, accepts: ~w(html json)],
  pubsub: [name: Chart.PubSub,
           adapter: Phoenix.PubSub.PG2]

# Configures Elixir's Logger
config :logger, :console,
  format: "$time $metadata[$level] $message\n",
  metadata: [:request_id]

import_config "#{Mix.env}.exs"  
## example app
use Mix.Config

config :example, ecto_repos: [Example.Repo]

config :example, Example.Repo,
  adapter: Ecto.Adapters.Postgres,
  database: "example_repo",
  hostname: "localhost" 

Here are the dependencies on the phoenix app ( example_web / chart )

defp deps do
  [
    {:phoenix, "~> 1.3.0"},
    {:phoenix_pubsub, "~> 1.0"},
    {:phoenix_html, "~> 2.10"},
    {:phoenix_live_reload, "~> 1.0", only: :dev},
    {:gettext, "~> 0.11"},
    {:cowboy, "~> 1.0"},
    { :example, path: "../example" }
  ]
end

And where do you start Example.Repo?

It’s a supervised application. So there is an application.ex file which kickstarts the Example.Repo process.

I am able to interact with the example app using the iex console. But when I try to integrate it with the phoenix app, I get this error.

Hope I was able to answer your question.

Maybe try moving repo configuration out of example and into example_web.

That works but having the repo config in example_web feels wrong to me. Let me explain why.

If I have two web apps, example_web1 and example_web2 both using the example elixir app, I wouldn’t want the config across two places.

Or may be I have got this all wrong in my head :confused:

Thanks for your help :+1:. Tomorrow I will give umbrella app a spin and see if it works.

All configs must be specified in the top-most application, including repo configs.

However, you can always ‘include’ the config from the dependency (it’s what I do… >.>).

Hi @overmindDL1, Thanks for your inputs :+1:

Can you expand on that a little. Does the same rule apply for an umbrella app ? I had a look at the https://github.com/wojtekmach/acme_bank/tree/master/apps/bank_web/config and it did not have any repo config.

Hey guys, I built an umbrella app to support the two apps, and the compilation error caused by ecto config is gone :tada:

Feels like magic to me though. Any guides, pointers here why one works and the other doesn’t ? :thinking:

2 Likes

As in if you have built two-standalone Apps and combine them into one project, you can just include (just like you include, say, dev.exs from the main config.exs) the ../deps/whateverproject/deps/config.exs or so. I build my projects like this, no umbrella needed. :slight_smile:

The first didn’t work because you didn’t specify it’s configurations in the top-level configs. ^.^;

1 Like