Add MusicLibrary.Notes.Note
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
defmodule MusicLibrary.Notes.Note do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
schema "notes" do
|
||||
field :entity, Ecto.Enum, values: [:record, :artist]
|
||||
field :content, :string
|
||||
field :musicbrainz_id, Ecto.UUID
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
def changeset(note, attrs) do
|
||||
note
|
||||
|> cast(attrs, [
|
||||
:entity,
|
||||
:content,
|
||||
:musicbrainz_id
|
||||
])
|
||||
|> validate_required([:entity, :content, :musicbrainz_id])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
defmodule MusicLibrary.Repo.Migrations.CreateNotes do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:notes, primary_key: false) do
|
||||
add :id, :binary_id, primary_key: true
|
||||
add :entity, :string, null: false
|
||||
add :musicbrainz_id, :uuid, null: false
|
||||
add :content, :string
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
create index(:notes, [:entity, :musicbrainz_id], unique: true)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user