Hi all,
How do you run equivelent of mix ash_postgres.migrate --tenants
with release inproduction? Something similar to this but for tenants
Run migrations _build/prod/rel/my_app/bin/my_app eval "MyApp.Release.migrate"
.
I have an application in production, and the new release has new tenants migrations. How do I run it?
Here is how I managed to run tenants migrations in productions. They could be a simpler way of doing it, but in case you are still looking for it, this might help you.
- Start your app in iex> with
_build/prod/rel/{my_app}/bin/{my_app} start_iex
- Run ecto migrations by passing tenant_migrations path like the following.
for tenant <- MyApp.Repo.all_tenants do
# Run the migrations for the tenant
migrations_path = "/{release_path}/lib/{MyApp}-{version}/priv/repo/tenant_migrations"
Ecto.Migrator.run(Hr.Repo, migrations_path, :up, all: true, prefix: tenant)
IO.puts("Migrations completed for tenant: #{tenant}")
end
There is an official way to do this.
It’s just not generated automatically.
You can find it here:
https://hexdocs.pm/ash_postgres/migrations-and-tasks.html#running-migrations-in-production
1 Like