feat: hopefully last part of persistence

This commit is contained in:
2026-04-23 16:06:36 +02:00
parent 82f2ed57dd
commit d3dda2bd40
3 changed files with 297 additions and 13 deletions

View File

@@ -0,0 +1,30 @@
defmodule BDS.Media.Translation do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :string, autogenerate: false}
@foreign_key_type :string
schema "media_translations" do
belongs_to :media, BDS.Media.Media, foreign_key: :translation_for, references: :id, type: :string
field :project_id, :string
field :language, :string
field :title, :string
field :alt, :string
field :caption, :string
field :created_at, :integer
field :updated_at, :integer
end
def changeset(translation, attrs) do
translation
|> cast(attrs, [:id, :project_id, :translation_for, :language, :title, :alt, :caption, :created_at, :updated_at],
empty_values: [nil]
)
|> validate_required([:id, :project_id, :translation_for, :language, :created_at, :updated_at])
|> foreign_key_constraint(:translation_for)
|> unique_constraint(:language, name: :media_translations_translation_language_idx)
end
end