Has anyone tried rolling back ecto migration in gigalixir.
Locally, it’s mix ecto.rollback
. In gigalixir it’s gigalixir ps:migrate
There doesn’t seem to have a rollback option. What options do I have?
Not a gigalixir user but it looks like ps:migrate is just a helper, maybe you could use the strategy used to deploy (and rollback) migrations in releases.
https://hexdocs.pm/ecto_sql/Ecto.Migrator.html#module-example-running-migrations-in-a-release
I would probably create a new migration that basically undo the previous one.
That sounds like a good feature request. We will add it to our list.
Here’s how to rollback ALL migrations: https://gigalixir.readthedocs.io/en/latest/database.html#how-to-reset-the-database
Basically:
- Drop into a remote console with
gigalixir ps:remote_console
- Run
Ecto.Migrator.run(MyApp.Repo, Application.app_dir(:my_app, "priv/repo/migrations"), :down, [all: true])
I believe you can rollback a single item with:
Ecto.Migrator.run(MyApp.Repo, Application.app_dir(:my_app, "priv/repo/migrations"), :down, [step: 1])
Be sure to use your app name from mix.exs instead of MyApp
and your app atom instead of :my_app
.
It appears there is now a #down
for Ecto.Migrator that might be useful.
More info here: Ecto.Migrator — Ecto SQL v3.8.3