Use Migrations to Create Database Tables

We have two schemas in our app, but we don’t have corresponding database tables yet. Luckily for us, Ecto includes migration support out of the box. This will feel similar to ActiveRecord migrations, so you’ll quickly be comfortable if you’ve used those before.

Migrations are scripts that modify your database. They are often used to add tables, add or modify columns, add indices, and so forth. You can even use migrations to update the data in your database, but this is an advanced case that we won’t cover in this book.

Let’s look at the basics of migrations and then define migrations for our two schemas.

Migration Basics

Ecto.Migration is implemented in a child library of Ecto called ecto_sql. This library ...

Get From Ruby to Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.