From 8f23a6bccb2c6e57edd6e18a626b459d52fad860 Mon Sep 17 00:00:00 2001 From: shibao Date: Mon, 25 Jul 2022 20:21:36 -0400 Subject: [PATCH] add context notes --- lib/memex/contexts/context_note.ex | 21 +++++++++++++++++++ .../20220726002129_create_context_notes.exs | 16 ++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 lib/memex/contexts/context_note.ex create mode 100644 priv/repo/migrations/20220726002129_create_context_notes.exs diff --git a/lib/memex/contexts/context_note.ex b/lib/memex/contexts/context_note.ex new file mode 100644 index 0000000..2c3e791 --- /dev/null +++ b/lib/memex/contexts/context_note.ex @@ -0,0 +1,21 @@ +defmodule Memex.Contexts.ContextNote do + use Ecto.Schema + import Ecto.Changeset + + @primary_key {:id, :binary_id, autogenerate: true} + @foreign_key_type :binary_id + schema "context_notes" do + + field :context_id, :binary_id + field :note_id, :binary_id + + timestamps() + end + + @doc false + def changeset(context_note, attrs) do + context_note + |> cast(attrs, []) + |> validate_required([]) + end +end diff --git a/priv/repo/migrations/20220726002129_create_context_notes.exs b/priv/repo/migrations/20220726002129_create_context_notes.exs new file mode 100644 index 0000000..6e7ff38 --- /dev/null +++ b/priv/repo/migrations/20220726002129_create_context_notes.exs @@ -0,0 +1,16 @@ +defmodule Memex.Repo.Migrations.CreateContextNotes do + use Ecto.Migration + + def change do + create table(:context_notes, primary_key: false) do + add :id, :binary_id, primary_key: true + add :context_id, references(:contexts, on_delete: :nothing, type: :binary_id) + add :note_id, references(:notes, on_delete: :nothing, type: :binary_id) + + timestamps() + end + + create index(:context_notes, [:context_id]) + create index(:context_notes, [:note_id]) + end +end