Skip to content

Commit

Permalink
Add check customization schema and migration
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Jan 23, 2025
1 parent 5209e42 commit b500da6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/wanda/catalog/check_customization.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule Wanda.Catalog.CheckCustomization do
@moduledoc """
Schema representing Customizations applied for a Check in a specific execution group.
"""
use Ecto.Schema
import Ecto.Changeset

@fields ~w(id check_id group_id inserted_at updated_at)a
@required_fields ~w(check_id group_id)a

@custom_value_fields ~w(name value)a

@primary_key false
schema "check_customizations" do
field :id, Ecto.UUID, primary_key: true
field :check_id, :string
field :group_id, Ecto.UUID

embeds_many :custom_values, CustomValue, primary_key: false do
field :name, :string
field :value, :string
end

timestamps(type: :utc_datetime_usec)
end


def changeset(check_customization, attrs) do
check_customization
|> cast(attrs, @fields)
|> validate_required(@required_fields)
|> cast_embed(:custom_values, with: &custom_value_changeset/2, required: true)
end

defp custom_value_changeset(custom_value, attrs) do
custom_value
|> cast(attrs, @custom_value_fields)
|> validate_required(@custom_value_fields)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule Wanda.Repo.Migrations.CreateCheckCustomizations do
use Ecto.Migration

def change do
create table(:check_customizations, primary_key: false) do
add :id, :uuid, primary_key: true
add :check_id, :string, null: false
add :group_id, :uuid, null: false
add :custom_values, :jsonb, null: false, default: "[]"

timestamps()
end

create index(:check_customizations, [:check_id])
create index(:check_customizations, [:group_id])
create unique_index(:check_customizations, [:check_id, :group_id])
end
end

0 comments on commit b500da6

Please sign in to comment.