From 97af827bc244a8998dfe8cbb620479be7ad59369 Mon Sep 17 00:00:00 2001 From: Joao P Dubas Date: Tue, 22 Jun 2021 23:55:02 +0000 Subject: [PATCH] [day-02] add user schema and migration Add elixir struct to represent an user and its corresponding representation on the database. --- lib/wabanex/user.ex | 13 +++++++++++++ .../20210622015725_create_users_table.exs | 15 +++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 lib/wabanex/user.ex create mode 100644 priv/repo/migrations/20210622015725_create_users_table.exs diff --git a/lib/wabanex/user.ex b/lib/wabanex/user.ex new file mode 100644 index 0000000..2403553 --- /dev/null +++ b/lib/wabanex/user.ex @@ -0,0 +1,13 @@ +defmodule Wabanex.User do + use Ecto.Schema + + @primary_key {:id, :binary_id, autogenerate: true} + + schema "users" do + field :name, :string + field :email, :string + field :password, :string + + timestamps() + end +end diff --git a/priv/repo/migrations/20210622015725_create_users_table.exs b/priv/repo/migrations/20210622015725_create_users_table.exs new file mode 100644 index 0000000..4e0745a --- /dev/null +++ b/priv/repo/migrations/20210622015725_create_users_table.exs @@ -0,0 +1,15 @@ +defmodule Wabanex.Repo.Migrations.CreateUsersTable do + use Ecto.Migration + + def change do + create table(:users) do + add :email, :string + add :name, :string + add :password, :string + + timestamps() + end + + create unique_index(:users, [:email]) + end +end