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

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
widianto
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews