earth7316

earth7316

Hi all

I have a Phoenix application that has it’s own Postgres database and also needs to communicate to a read only database on a different machine to get catalog type of data. This works fine and I’ve setup my application with two Repo’s and can retrieve data.

The problem I’m running into is with running
mix test

this is attempting to use a test database that doesn’t exist (and can’t really as the read only database is a huge legacy system of record for multiple applications). I know with ecto.migrate I can pass a -r flag to say which Repo to use but when running tests that flag doesn’t seem to exist.

Can anyone point me to some documentation on this?

BTW even the -r flag is a bit wonky in my opinion. I would think having a flag in the configuration to say the database is read only so don’t try and use it for generators, migrations or tests would be a much cleaner integration and potentially avoid risk of accidentally running mix ecto.reset and having it cascade inadvertently to a database that wasn’t meant for dropping (I realize you could have a different db user that’s read only but for development it’s not always easy to get an operations team member to do things like add users to a database).

Thanks for any help.

Showing Posts 1 to 5

NobbZ

NobbZ

Create a dummy database for that read-only one.

Unless your tests are directly or indirectly relying on data in that database it will work if you leave it empty I think. If not you need to fill in some stub data.

earth7316

earth7316 OP

Thanks Nobbz that works but is kind of wonky for my needs. I discovered though that I can modify the aliases in mix.exs to do what I need for this scenario which is migrations, reset, create, drop ONLY apply to my database and not my read replica that I use for ancillary data and is not part of this applications CRUD operations. So I did this and it works great

  defp aliases do
    [
      "ecto.setup": ["ecto.create -r MyApp.Repo", "ecto.migrate -r MyApp.Repo", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop -r MyApp.Repo", "ecto.setup -r MyApp.Repo"],
      "test": ["ecto.create --quiet", "ecto.migrate", "test"]
    ]
  end
josevalim

josevalim

Creator of Elixir

There is a configuration in your config files named ecto_repos. If you don’t pass the --repo/-r flags, only the repositories listed there will be set up, migrated, etc. You should be able to set the config to an empty list, change it per environment, etc.

earth7316

earth7316 OP

Ah thanks Jose - much better!!

vineetv2821993

vineetv2821993

Sorry for joining late. Follow this post: Using Multiple DBs in Phoenix · Blog

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews