3 ms·
For Ecto, you can just run a function: migrations_path = Path.join(["#{:code.priv_dir(:myapp)}", "repo", "migrations"]) Ecto.Migrator.run(MyApp.Repo, migra
by l72 6y ago
For Ecto, you can just run a function:
migrations_path = Path.join(["#{:code.priv_dir(:myapp)}", "repo", "migrations"])
Ecto.Migrator.run(MyApp.Repo, migrations_path, :up, all: true)
Since migrations are idempotent, and I always want to run up to the latest migration, I just include this in lib/myapp.ex in its start function. That way any time a new release rolls out, the first node with the new release automatically runs the migrations. (We always make sure our migrations are backwards compatible for at least X number of versions, which means never deleting tables or columns so that existing nodes don't break)