Specifying Up and Down Operations
In the last section, we created a migration that altered data as well as structure, but we left out an important step. In its current form, this migration can’t be rolled back.
Ecto can’t reverse the removal of a column, because it wouldn’t know what type it should be restored back to. And we certainly can’t expect Ecto to figure out how to reverse the data transformation we did between compositions and compositions_artists. We need to specify the rollback instructions ourselves.
In cases like these, you write the migration differently. Instead of providing a single change function, you write an up function and a down function, to handle the migration going forward and rolling back, respectively. Let’s rewrite ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access