From 912fab9a9601253c361955b996fe3762b44e832e Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Fri, 17 Dec 2021 13:25:14 -0500 Subject: [PATCH] fix: use `CiStringWrapper` type in ash_postgres --- lib/data_layer.ex | 4 ++++ lib/types/ci_string_wrapper.ex | 14 ++++++++++++++ test/support/resources/comment.ex | 4 ++++ 3 files changed, 22 insertions(+) create mode 100644 lib/types/ci_string_wrapper.ex diff --git a/lib/data_layer.ex b/lib/data_layer.ex index c237847..6b0fb8c 100644 --- a/lib/data_layer.ex +++ b/lib/data_layer.ex @@ -1601,6 +1601,10 @@ defmodule AshPostgres.DataLayer do {:array, parameterized_type(type, constraints[:items] || [])} end + defp parameterized_type(Ash.Type.CiString, constraints) do + parameterized_type(Ash.Type.CiStringWrapper, constraints) + end + defp parameterized_type(type, constraints) do if Ash.Type.ash_type?(type) do parameterized_type(Ash.Type.ecto_type(type), constraints) diff --git a/lib/types/ci_string_wrapper.ex b/lib/types/ci_string_wrapper.ex new file mode 100644 index 0000000..4abe3ca --- /dev/null +++ b/lib/types/ci_string_wrapper.ex @@ -0,0 +1,14 @@ +defmodule Ash.Type.CiStringWrapper do + @moduledoc false + use Ash.Type + + @impl true + def storage_type, do: :citext + + @impl true + defdelegate cast_input(value, constraints), to: Ash.Type.CiString + @impl true + defdelegate cast_stored(value, constraints), to: Ash.Type.CiString + @impl true + defdelegate dump_to_native(value, constraints), to: Ash.Type.CiString +end diff --git a/test/support/resources/comment.ex b/test/support/resources/comment.ex index 7bda3bf..8169a20 100644 --- a/test/support/resources/comment.ex +++ b/test/support/resources/comment.ex @@ -30,6 +30,10 @@ defmodule AshPostgres.Test.Comment do create_timestamp(:created_at) end + aggregates do + first(:post_category, :post, :category) + end + relationships do belongs_to(:post, AshPostgres.Test.Post) belongs_to(:author, AshPostgres.Test.Author)