-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check customization schema and migration
- Loading branch information
1 parent
5209e42
commit b6706aa
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
priv/repo/migrations/20250123102550_create_check_customizations.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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 | ||
end | ||
end |