add context notes

This commit is contained in:
shibao 2022-07-25 20:21:36 -04:00
parent 52e5e02ab6
commit 8f23a6bccb
2 changed files with 37 additions and 0 deletions

View File

@ -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

View File

@ -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