I have a phoenix application that has standard Repo setup and uses postgresql.
I want to connect it to second database that is read_only: true
. I manage to do this with the following config
# config/config.exs
config :my_app,
ecto_repos: [MyApp.Repo, MyApp.SecondRepo],
config :my_app, MyApp.Repo,
url: "...."
config :my_app, MyApp.SecondRepo,
url: "..."
and the config for the two Repos
My main repository
# lib/my_app/repo.ex
defmodule MyApp.Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.Postgres
end
My second repository (read_only: true)
# lib/my_app/second_repo.ex
defmodule MyApp.SecondRepo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.Postgres,
read_only: true
end
I create also priv/second_repo/migrations
folder.
However this approach seems to cause the creation of schema_migrations
in the database for the SecondRepo.
I try to avoid this by pointing the SecondRepo
# config/config.exs
...
config :my_app, MyApp.SecondRepo,
url: "...",
migration_repo: MyApp.Repo
This seems to be half working but now every time when I try to run
mix ecto.gen.migration ...
or mix ecto.migrate
or mix ecto.rollback
it seems to try to run the same migration two times.
I was wondering if there is some way to disable the check for the schema_migrations
I saw this question but it seems this approach still creates the schema_migrations.