Compare commits

..

1 commit

Author SHA1 Message Date
d085d80f74
feat: property value as Union type
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-22 01:58:39 +02:00
10 changed files with 33 additions and 60 deletions

View file

@ -33,21 +33,3 @@ test:
format:
mix format
regen-migrations migration_name:
#!/bin/bash
set -euo pipefail
# Get count of untracked migrations
N_MIGRATIONS=$(git ls-files --others priv/repo/migrations | wc -l)
# Rollback untracked migrations
mix ash_postgres.rollback -n $N_MIGRATIONS
# Delete untracked migrations and snapshots
git ls-files --others priv/repo/migrations | xargs rm
git ls-files --others priv/resource_snapshots | xargs rm
# Regenerate migrations
mix ash.codegen --name {{migration_name}}
# Run migrations if flag
if echo $* | grep -e "-m" -q; then
mix ash.migrate
fi

View file

@ -20,9 +20,9 @@ defmodule Mv.Membership.Property do
constraints: [
storage: :type_and_value,
types: [
boolean: [type: :boolean],
bool: [type: :boolean],
date: [type: :date],
integer: [type: :integer],
int: [type: :integer],
string: [type: :string]
]
]

View file

@ -10,7 +10,7 @@ defmodule Mv.Membership.PropertyType do
actions do
defaults [:create, :read, :update, :destroy]
default_accept [:name, :value_type, :description, :immutable, :required]
default_accept [:name, :type, :description, :immutable, :required]
end
attributes do
@ -18,8 +18,7 @@ defmodule Mv.Membership.PropertyType do
attribute :name, :string, allow_nil?: false, public?: true
attribute :value_type, :atom,
constraints: [one_of: [:string, :integer, :boolean, :date]],
attribute :type, :string,
allow_nil?: false,
description: "Definies the datatype `Property.value` is interpreted as"

View file

@ -10,9 +10,9 @@ defmodule MvWeb.MemberLive.FormComponent do
%{
"property_type_id" => pt.id,
"value" => %{
"type" => pt.value_type,
"type" => String.to_existing_atom(pt.type),
"value" => nil,
"_union_type" => Atom.to_string(pt.value_type)
"_union_type" => pt.type
}
}
end)
@ -39,13 +39,7 @@ defmodule MvWeb.MemberLive.FormComponent do
<.inputs_for :let={f_property} field={@form[:properties]}>
<% type = Enum.find(@property_types, &(&1.id == f_property[:property_type_id].value)) %>
<.inputs_for :let={value_form} field={f_property[:value]}>
<% input_type =
cond do
type && type.value_type == :boolean -> "checkbox"
type && type.value_type == :date -> :date
true -> :text
end %>
<.input field={value_form[:value]} label={type && type.name} type={input_type} />
<.input field={value_form[:value]} label={type && type.name} />
</.inputs_for>
<input
type="hidden"

View file

@ -11,7 +11,7 @@ defmodule Mv.Repo.Migrations.InitialMigration do
create table(:property_types, primary_key: false) do
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
add :name, :text, null: false
add :value_type, :text, null: false
add :type, :text, null: false
add :description, :text
add :immutable, :boolean, null: false, default: false
add :required, :boolean, null: false, default: false

View file

@ -15,35 +15,14 @@ alias Mv.Membership
for attrs <- [
%{
name: "Vorname",
value_type: :string,
type: "string",
description: "Vorname des Mitglieds",
immutable: true,
required: true
},
%{
name: "Nachname",
value_type: :string,
description: "Nachname des Mitglieds",
immutable: true,
required: true
},
%{
name: "Geburtsdatum",
value_type: :date,
description: "Geburtsdatum des Mitglieds",
immutable: true,
required: true
},
%{
name: "Bezahlt",
value_type: :boolean,
description: "Status des Mitgliedsbeitrages des Mitglieds",
immutable: true,
required: true
},
%{
name: "Email",
value_type: :string,
type: "string",
description: "Email-Adresse des Mitglieds",
immutable: true,
required: true

View file

@ -16,7 +16,7 @@
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "35D45214D6D344B0AF6CFCB69B8682FCB3D382D85883D3D3AAC1AEE7F54FD89A",
"hash": "A0402269CB456075B81CA4CB3A2135A2C88D8B7FD51CD7A23084AA5264FEE344",
"identities": [],
"multitenancy": {
"attribute": null,

View file

@ -84,7 +84,7 @@
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "8CF241CB9E8239511914EDEC96186BB7879529372BD8A4162431CCE9961F4F1B",
"hash": "4D127B8DA5051633CE92D4C94B1C3D76FCBD2EE992EF8318B977E5C2B8CF19E4",
"identities": [],
"multitenancy": {
"attribute": null,

View file

@ -27,7 +27,7 @@
"primary_key?": false,
"references": null,
"size": null,
"source": "value_type",
"source": "type",
"type": "text"
},
{
@ -66,7 +66,7 @@
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "F98A723AE0D20005FBE4205E46ABEE09A88DFF9334C85BADC1FBEEF100F3E25B",
"hash": "47210108DE1E7B2A20A67205E875B3440526941E61AB95B166976E8CD8AA0955",
"identities": [
{
"all_tenants?": false,

19
regen_migrations.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash
# Get count of untracked migrations
N_MIGRATIONS=$(git ls-files --others priv/repo/migrations | wc -l)
# Rollback untracked migrations
mix ash_postgres.rollback -n $N_MIGRATIONS
# Delete untracked migrations and snapshots
git ls-files --others priv/repo/migrations | xargs rm
git ls-files --others priv/resource_snapshots | xargs rm
# Regenerate migrations
mix ash.codegen --name $1
# Run migrations if flag
if echo $* | grep -e "-m" -q; then
mix ash.migrate
fi