Phoenix + Ecto Start Another Repo

Hello hello!

I have a small CRUD project with with two separate mix files (applications) for separation of concerns.

--- browser(Phoenix Liveview Front End)
--- blog (All of the CRUD business logic and DB)

The blog has a functioning Blog.Repo, but I don’t quite understand how to start/find this repo when starting mix phx.server in Blog_App/browser.

My error-

could not lookup Ecto repo Blog.Repo because it was not started or it does not exist

I’ve tried-

in Browser’s mix.exs setting the deps

{:blog, path: "../blog"}


setting Blog.Repo as one of the children to start in browser’s application.ex.

Any ideas or tips?

Thanks for any help :smile:

You also need to configure Blog.Repo in Browser…

Phoenix does already this separation of concern, with App, AppWeb.

It’s meant to separate Core Business Logic, and Web interface.

I am also curious how You build your Blog part. Is it a simple mix new project --sup?

Ha yes, I’m just trying to separate the concerns even further :wink:

Correct, Blog has it’s own Supervisor tree already implemented from the boiler plate mix new project --sup command

It’s possible and I do it very often…

But Blog’s config needs to be duplicated in the Browser’s config.

Ah! That makes sense to edit in the config file. The error is gone now. I just added it like this-


config :browser,
  ecto_repos: [Browser.Repo]

config :blog, Blog.Repo,
  database: "blog_repo",
  username: "postgres",
  password: "pass",
  hostname: "localhost"

config :blog,
  ecto_repos: [Blog.Repo]

Just copied and pasted the config from blog/config.exs. That’s what you’re talking about, right?

yes, that’s it…

1 Like

Thanks Koko! :two_hearts:

1 Like