Ecto.Migrator.with_repo

You're seeing just the function with_repo, go back to Ecto.Migrator module for more information.
Link to this function

with_repo(repo, fun, opts \\ [])

View Source

Ensures the repo is started to perform migration operations.

All of the application required to run the repo will be started before hand with chosen mode. If the repo has not yet been started, it is manually started, with a :pool_size of 2, before the given function is executed, and the repo is then terminated. If the repo was already started, then the function is directly executed, without terminating the repo afterwards.

Although this function was designed to start repositories for running migrations, it can be used by any code, Mix task, or release tooling that needs to briefly start a repository to perform a certain operation and then terminate.

The repo may also configure a :start_apps_before_migration option which is a list of applications to be started before the migration runs.

It returns {:ok, fun_return, apps}, with all apps that have been started, or {:error, term}.

Options

  • :pool_size - The pool size to start the repo for migrations. Defaults to 2.
  • :mode - The mode to start all applications. Defaults to :permanent.

Examples

{:ok, _, _} =
  Ecto.Migrator.with_repo(repo, fn repo ->
    Ecto.Migrator.run(repo, :up, all: true)
  end)