earth7316

earth7316

Ecto/Phoenix/Mix with multiple databases

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.

Most Liked

vineetv2821993

vineetv2821993

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

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.

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.

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement