feat: Add validation constraints and tests for CustomField and CustomFieldValue

This commit is contained in:
Moritz 2025-11-13 18:37:58 +01:00
parent 8400e727a7
commit e9290b7156
4 changed files with 523 additions and 9 deletions

View file

@ -30,6 +30,11 @@ defmodule Mv.Membership.CustomFieldValue do
## Constraints
- Each member can have only one custom field value per custom field (unique composite index)
- Custom field values are deleted when the associated member is deleted (CASCADE)
- String values maximum length: 10,000 characters
- Email values maximum length: 254 characters (RFC 5321)
## Future Features
- Type-matching validation (value type must match custom field's value_type) - to be implemented
"""
use Ash.Resource,
domain: Mv.Membership,
@ -56,11 +61,25 @@ defmodule Mv.Membership.CustomFieldValue do
constraints: [
storage: :type_and_value,
types: [
boolean: [type: :boolean],
date: [type: :date],
integer: [type: :integer],
string: [type: :string],
email: [type: Mv.Membership.Email]
boolean: [
type: :boolean
],
date: [
type: :date
],
integer: [
type: :integer
],
string: [
type: :string,
constraints: [
max_length: 10_000,
trim?: true
]
],
email: [
type: Mv.Membership.Email
]
]
]
end