New Phoenix web project does not load Repo

In an umbrella, there is an elixir app that encapsulates the business logic for a prototype project.

Still in early phase, some “stakeholders” can benefit from a simple form where they can:

  • experiment with inserting in-/valid inputs
  • see the outputs that the business logic app returns

For this purpose, creating a new Phoenix web project within the umbrella project seems to fit:

$ mix phx.new.web foo --no-brunch

Changing into the new app directory and running mix phx.server successfully displays the Welcome to Phoenix! page. When running mix test though, the following error is returned:

** (Mix) Could not load Foo.Repo, error: :nofile. Please configure your app accordingly or pass a repo with the -r option.

I traced back as far as the alias calling ecto.create and to Mix.Ecto.ensure_repo/2.

Can anyone guide this novice’s path further, please?

Running:

  • ecto 2.2.7
  • phoenix 1.3.0
  • elixir 1.5.2
  • erlang 20.1
1 Like

is config/test.exs configured so it can connect to the db?

1 Like

Looks like it is not: it only contains only the content generated by default:

# …/apps/foo/config/test.exs
use Mix.Config

# We don't run a server during test. If one is required,
# you can enable the server option below.
config :test_harness, TestHarness.Endpoint,
  http: [port: 4001],
  server: false

Given the required simplicity – a simple form – how can this be configured such that it does not require a connection to the DB?

1 Like

comment out the ecto.adapter setup things in the test files.

if you don’t use ecto maybe use the --no-ecto when creating the project… see https://hexdocs.pm/phoenix/ecto.html

4 Likes

If you don’t want to have the DB at all, don’t start Foo.Repo in your application.ex

2 Likes

Thank you @ryh, I believe your suggestion is along the lines of removing supervisor(Foo.Repo, []).

Creating a new Phoenix web project with mix phx.new.web does not add that though. :thumbsup:

1 Like

Searched the generated codebase for all references to Foo.Repo and commented out the respective chunks of logic. This seems to have worked, thank you! :thumbsup:


As for the --no-ecto flag, it is not an option in this case: Ecto is needed for schemas and validation. It’s just the database layer (Repo?) that is unnecessary.

3 Likes