Update media_attachment
This commit is contained in:
parent
4929ce21fd
commit
867f94572d
2 changed files with 25 additions and 10 deletions
|
@ -5,18 +5,30 @@ defmodule Nulla.Models.MediaAttachment do
|
|||
|
||||
@primary_key {:id, :integer, autogenerate: false}
|
||||
schema "media_attachments" do
|
||||
field :file, :string
|
||||
field :mime_type, :string
|
||||
field :description, :string
|
||||
field :type, :string
|
||||
field :mediaType, :string
|
||||
field :url, :string
|
||||
field :name, :string
|
||||
field :width, :integer
|
||||
field :height, :integer
|
||||
|
||||
belongs_to :note, Note
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
def changeset(media, attrs) do
|
||||
media
|
||||
|> cast(attrs, [:note_id, :file, :mime_type, :description])
|
||||
|> validate_required([:note_id, :file])
|
||||
def changeset(media_attachment, attrs) do
|
||||
media_attachment
|
||||
|> cast(attrs, [:type, :mediaType, :url, :name, :width, :height, :note_id])
|
||||
|> validate_required([:type, :mediaType, :url, :note_id])
|
||||
end
|
||||
|
||||
def create_media_attachment(attrs) when is_map(attrs) do
|
||||
id = Map.get(attrs, :id, Snowflake.next_id())
|
||||
|
||||
%__MODULE__{}
|
||||
|> changeset(attrs)
|
||||
|> put_change(:id, id)
|
||||
|> Repo.insert()
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,10 +4,13 @@ defmodule Nulla.Repo.Migrations.CreateMediaAttachments do
|
|||
def change do
|
||||
create table(:media_attachments, primary_key: false) do
|
||||
add :id, :bigint, primary_key: true
|
||||
add :type, :string, null: false
|
||||
add :mediaType, :string, null: false
|
||||
add :url, :string, null: false
|
||||
add :name, :string
|
||||
add :width, :integer
|
||||
add :height, :integer
|
||||
add :note_id, references(:notes, on_delete: :delete_all), null: false
|
||||
add :file, :string, null: false
|
||||
add :mime_type, :string
|
||||
add :description, :string
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue