i-n-g-m-a-r
I am thinking about doing something like this:
defmodule MyApp.Application do
use Application
def start(_type, _args) do
children = [MyApp.Repo]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
with {:ok, pid} <- Supervisor.start_link(children, opts) do
MyApp.Repo.run_migrations()
{:ok, pid}
end
end
end
defmodule MyApp.Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.Postgres
def run_migrations, do:
Ecto.Migrator.run(__MODULE__, migrations_path(), :up, all: true)
defp migrations_path, do:
Path.join[:code.priv_dir(:my_app), "repo", "migrations"])
end
Would that cause any problems?
Trending in Questions
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
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
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
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
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Other Trending Topics
I’ve released the first beta of Draught, a coding-agent CLI and runtime built with Elixir.
Draught can run agentic coding tasks using Ol...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
If anything, I would run migrations before starting application, as this can cause data race.
hauleth
BTW if you want to run something after application starts then you can use
:start_phasesinapplication/0(I have blogpost about this that I want to publish soon).i-n-g-m-a-r
Data races would only occur when something would use the application right?
The main reason I’m thinking of doing this, is to have dependencies run their own migrations automatically when the dependent application starts.
So the dependency would be listed in
extra_applicationsand would start first (and run migrations) before the dependent application (the user) starts.I figured that capturing the return value
{:ok, pid}and running migrations before returning it, would be ok.I’m very interested in your upcoming post.
hauleth
In case of application that is dependency I would do not contain any
Reponor migrations directly but instead I would provide migration generator. Like Oban does for example.i-n-g-m-a-r
I didn’t find any multi database / multi git repo Elixir application, so this is kind of an experiment.
Probably micro services with Kubernetes or something like that would be “better” though that’s not the kind of complexity I’m looking for.
I looked into umbrella applications but I don’t like that approach.
Also running multiple applications behind a reverse proxy would just add complexity and more boundaries.
So far the dependency strategy has worked very well with a GraphQL frontend as the dependent and resolvers calling the dependencies (backends).
LostKobrakai
The important part here is that a database is a singleton and you want to keep control over it in one place. This usually is the application with the
MyApp.Repo. Any libraries forMyAppshould not migrate anything on their own, but only supply easy to use API toMyAppto integrate into its own migrations. This makes debugging and reason about the database state way more sane than having to look in each and every dependency what make your application break if that happens.Also I’m not really sure how this should be related to umbrella projects/kubernetes.
i-n-g-m-a-r
In case of many databases the database is not a singleton, that’s the point.
So there will be many repo’s.
Databases know if they need migrations or if they are already up.
Qqwy
I find this a really interesting question.
I think that in production, it might make sense to (automatically) run migrations once a deployment has finished.
In development, however, not so much. I think there are many situations in which I do not want to run a migration yet. For instance:
i-n-g-m-a-r
The example is very basic, in practice the application should also be able to rollback and so on.
Only when an application is ready to use and well
tested (seperately) it’s plugged into the frontend as a dependency.