Migrations

As we've already seen, the purpose of our Media schema is to represent the data that we retrieve from the database in the Elixir world. Since we are using a relational database, data is persisted in database tables.

To create the tables, instead of executing a SQL script directly on the database, we will use Ecto migrations to apply every database schema change for us.

Migrations live on the priv/repo/migrations folder as Elixir scripts and their name should abide by the <timestamp>_<snake_case_name>.exs format, for example 20180112095312_create_media.exs. To execute a migration or roll back an existing one, you should use ecto.migrate or ecto.rollback, respectively.

Here's the CreateMedia migration responsible for the creation ...

Get Mastering 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.