Schemas and migrations
Given we are now connected to the database, we will set the data foundations of our project. In this section, we'll create the schemas that represent our users and their media, and the corresponding data migrations.
Schemas
Our ElixirDrip project allows users to safely store their media, and eventually share it with other users. Therefore, we need to have a way to represent users and media as database tables.
To help developers with this, Ecto has the schema construct. Its purpose is to establish a mapping between any information stored in the database and its representation in Elixir data structures.
Â
Let's define the schema to represent the users' media:
$ cat apps/elixir_drip/lib/elixir_drip/storage/media.ex defmodule ElixirDrip.Storage.Media do use Ecto.Schema schema "storage_media" do field :user_id, :id field :file_name, :string field :full_path, :string field :file_size, :integer field :metadata, :map, default: %{} field :encryption_key...