Exclude repo from `mix ecto.*` tasks

Hi,

I’m fairly new to Elixir and Phoenix, maybe the answer is easy but I didn’t find it in
the forum nor in the documentation.

Right now I’m developing an helper app that needs to access, alongside his own Postgres database (Repo), two more legacy databases (SQL Server) in read only mode.
I set up the two legacy repos, RepoWeb and RepoUsers, both with read_only: true and excluded them from ector_repos in application.exs

My question is: it is safe to run the ecto tasks (drop, create, reset) or the tasks will try to drop and recreate the two legacy databases too?

When I try to run the tasks without internet connection the task still try to access the two legacy databases.

$mix ecto.reset
The database for Agostino.Repo has been dropped
The database for Agostino.Repo has been created

19:10:37.574 [info] Migrations already up
[notice]     :alarm_handler: {:set, {:system_memory_high_watermark, []}}
[error] Tds.Protocol (#PID<0.520.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.535.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.525.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.540.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.534.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.521.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.519.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.537.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.522.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.532.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.538.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.541.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.539.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.524.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.528.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.536.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.533.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.527.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.526.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[error] Tds.Protocol (#PID<0.523.0>) failed to connect: ** (Tds.Error) tcp connect: enetunreach
[info] Running AgostinoWeb.Endpoint with cowboy 2.9.0 at 127.0.0.1:4000 (http)
[info] Access AgostinoWeb.Endpoint at http://localhost:4000
[watch] build finished, watching for changes...
[info] start link
Agostino.Redix.PubSub
#Reference<0.1597631740.2464153601.77013>
[os_mon] memory supervisor port (memsup): Erlang has closed
[os_mon] cpu supervisor port (cpu_sup): Erlang has closed

Thanks in advance

Frank

1 Like

It should be safe, however I would not risk it, just create users with only read privileges to be safe.

This is what I do for now but the problem is that in the future I will need write permissions anyway and I want to be sure to not destroy the database.

Another way could be to have an umbrella so the legacy repo will not be started when I execute the tasks, maybe?

Some ecto mix tasks take an -r option that lets you target a specific repo.

For example, when dropping the database:

mix ecto.drop

… if the -r option is given, it replaces the :ecto_repos config.

mix ecto.drop -r Custom.Repo

Command line options

  • -r, --repo - the repo to drop

source: mix ecto.drop — Ecto v3.11.1

As well as when running migrations:

mix ecto.migrate

… if the -r option is given, it replaces the :ecto_repos config.

mix ecto.migrate -r Custom.Repo

Command line options

  • -r, --repo - the repo to migrate

source: mix ecto.migrate — Ecto SQL v3.11.1

1 Like

yes I know this, what I’m looking for is a failsafe, a way to exclude a repo not a way to operate on a specific one.

Anywho in the end I went with the umbrella way, probably not the best but it works.

I still think would like to know, from someone who really know, if this is possible or not

Thanks,
Frank

Just read the documentation, it is clearly specified there how everything works.

Actually I read it, and some of the source code too, my understanding is that it should be safe but, then, a new question arise:
why, even if the legacy repo is not in :ecto_repos, mix ecto.create/drop try to start it anyway?

And there is no trace of this behaviour in the mix ecto docs