Gulliver
Hi,
I’m trying to figure out how to use a single database app in my umbrella project to take care of everything db related.
My app structure is like this:
umbrella project
|
– Database_app
|
– Phoenix_app
|
– App_1
Now, I define a schema “Banana” in “App_1” and I would like to use it with a repo from “database app”.
Everything else works ok but I can’t figure out how to deal with migrations? In my example case they should be in “App_1”, but when I try to create a migration with “mix ecto.gen.migration create_bananas” in “App_1” I either get an error “warning: could not find repositories for application …” without anything in my config file, or “(Mix) Could not load Database_App.Repo, error: :nofile. Please configure your app accordingly or pass a repo with the -r option” when I use the following config:
config :App_1, Database_App.Repo,
adapter: Ecto.Adapters.Postgres,
database: "mydatabase",
username: "username",
password: "password",
hostname: "localhost"
config :app_1, ecto_repos: [Database_App.Repo]
So what am I doing wrong here, how could I config this app_1 so that it would have the schema and the migrations but use the repo from another app, is it even possible?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
wojtekmach
While it’s possible to access Repo from another app, I’d advise against that in most cases - to me it looks like breaking boundaries between the apps. I don’t know the details about your particular project, but I’d probably start with just 2 apps:
App1&Phoenix_app, andApp1would “own” the data & storage and hide these implementation details (schemas, queries, access to Repo) behind a well defined interface. And in the future if you’d want to addApp2I’d actually create a separateApp2.Repo(that can use a different or the same underlying DB). The idea would be that each app is independent and isolated from each other as much as possible an the implementation details (e.g. Repo) don’t leak out.P.S. you might have a typo in configuration:
config :App_1vsconfig :app_1so maybe this is the reason you can’t run the migrations.Gulliver
Thanks for your help. I’ll take your advice and restructure my project in a way that every app talks directly to the db. And about the typo, those names were just something I pulled out of my hat, not from the real project where they are (should be..) correct, but thanks anyway.