From a38d13a16a1f9b609a48618e167812327bdc1ec0 Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Sat, 27 Jul 2024 23:22:09 +0500 Subject: [PATCH] feat: notes schema --- lib/comfycamp/note.ex | 18 ++++++++++++++++++ .../migrations/20240725083222_create_notes.exs | 12 ++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 lib/comfycamp/note.ex create mode 100644 priv/repo/migrations/20240725083222_create_notes.exs diff --git a/lib/comfycamp/note.ex b/lib/comfycamp/note.ex new file mode 100644 index 0000000..3042fcb --- /dev/null +++ b/lib/comfycamp/note.ex @@ -0,0 +1,18 @@ +defmodule Comfycamp.Note do + use Ecto.Schema + import Ecto.Changeset + + schema "notes" do + field :title, :string + field :markdown, :string + + timestamps(type: :utc_datetime) + end + + @doc false + def changeset(note, attrs) do + note + |> cast(attrs, [:title, :markdown]) + |> validate_required([:title, :markdown]) + end +end diff --git a/priv/repo/migrations/20240725083222_create_notes.exs b/priv/repo/migrations/20240725083222_create_notes.exs new file mode 100644 index 0000000..9409a99 --- /dev/null +++ b/priv/repo/migrations/20240725083222_create_notes.exs @@ -0,0 +1,12 @@ +defmodule Comfycamp.Repo.Migrations.CreateNotes do + use Ecto.Migration + + def change do + create table(:notes) do + add :title, :string + add :markdown, :string + + timestamps(type: :utc_datetime) + end + end +end