add container tags
This commit is contained in:
parent
f12e71cbe2
commit
48691e669e
31
lib/cannery/containers/container_tag.ex
Normal file
31
lib/cannery/containers/container_tag.ex
Normal file
@ -0,0 +1,31 @@
|
||||
defmodule Cannery.Containers.ContainerTag do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Cannery.{Containers, Tags}
|
||||
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
@foreign_key_type :binary_id
|
||||
schema "container_tags" do
|
||||
belongs_to :container, Containers.Container
|
||||
belongs_to :tag, Tags.Tag
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@type t :: %{
|
||||
id: Ecto.UUID.t(),
|
||||
container: Containers.Container.t(),
|
||||
container_id: Ecto.UUID.t(),
|
||||
tag: Tags.Tag.t(),
|
||||
tag_id: Ecto.UUID.t(),
|
||||
inserted_at: NaiveDateTime.t(),
|
||||
updated_at: NaiveDateTime.t()
|
||||
}
|
||||
|
||||
@doc false
|
||||
def changeset(container_tag, attrs) do
|
||||
container_tag
|
||||
|> cast(attrs, [:tag_id, :container_id])
|
||||
|> validate_required([:tag_id, :container_id])
|
||||
end
|
||||
end
|
@ -0,0 +1,17 @@
|
||||
defmodule Cannery.Repo.Migrations.CreateContainerTags do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:container_tags, primary_key: false) do
|
||||
add :id, :binary_id, primary_key: true
|
||||
|
||||
add :container_id, references(:containers, on_delete: :delete_all, type: :binary_id)
|
||||
add :tag_id, references(:tags, on_delete: :delete_all, type: :binary_id)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index(:container_tags, [:container_id])
|
||||
create index(:container_tags, [:tag_id])
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user