I’m still struggling with how to completely reset my database in production (not really production, but a production-like environment running in prod
mode on Fly.io)
I have added a reset
method to lib/myapp/release.ex
as follows:
defmodule Myapp.Release do
@moduledoc """
Used for executing DB release tasks when run in production without Mix
installed.
"""
@app :myapp
def migrate do
load_app()
for repo <- repos() do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end
def rollback(repo, version) do
load_app()
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end
def reset do
load_app()
IO.inspect('+----------------------------------------------+')
IO.inspect('| DROPPING ALL DATA AND RESETTING THE DATABASE |')
IO.inspect('+----------------------------------------------+')
for repo <- repos() do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, all: true))
end
migrate()
end
defp repos do
Application.fetch_env!(@app, :ecto_repos)
end
defp load_app do
Application.load(@app)
end
end
The reset
method should basically just run all the down migrations.
My problem is that the local branch that I’m working on has completely different migration files now – I have deleted all the old migration files that were previously deployed to production and I now have completely new database migration files.
So I want to write a custom “down migration” that my reset method will run, and I want it to just say “drop all database tables and indexes and any other database objects”. Does anyone know what the incantation for this might be?
Thanks.