From 9f62d65215a6a22f657600baa23ae979ea5d61cf Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Tue, 10 Oct 2023 14:12:25 -0400 Subject: [PATCH] improvement: support `:ci_string` as a storage_type --- lib/migration_generator/migration_generator.ex | 1 + lib/types/ci_string_wrapper copy.ex | 14 -------------- lib/types/ci_string_wrapper.ex | 10 +++++----- lib/types/string_wrapper.ex | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 19 deletions(-) delete mode 100644 lib/types/ci_string_wrapper copy.ex create mode 100644 lib/types/string_wrapper.ex diff --git a/lib/migration_generator/migration_generator.ex b/lib/migration_generator/migration_generator.ex index 2fc59c63..a15a058f 100644 --- a/lib/migration_generator/migration_generator.ex +++ b/lib/migration_generator/migration_generator.ex @@ -2743,6 +2743,7 @@ defmodule AshPostgres.MigrationGenerator do end defp migration_type_from_storage_type(:string), do: :text + defp migration_type_from_storage_type(:ci_string), do: :citext defp migration_type_from_storage_type(storage_type), do: storage_type defp foreign_key?(relationship) do diff --git a/lib/types/ci_string_wrapper copy.ex b/lib/types/ci_string_wrapper copy.ex deleted file mode 100644 index 72f850d4..00000000 --- a/lib/types/ci_string_wrapper copy.ex +++ /dev/null @@ -1,14 +0,0 @@ -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/lib/types/ci_string_wrapper.ex b/lib/types/ci_string_wrapper.ex index 82d067da..72f850d4 100644 --- a/lib/types/ci_string_wrapper.ex +++ b/lib/types/ci_string_wrapper.ex @@ -1,14 +1,14 @@ -defmodule Ash.Type.StringWrapper do +defmodule Ash.Type.CiStringWrapper do @moduledoc false use Ash.Type @impl true - def storage_type(_), do: :text + def storage_type(_), do: :citext @impl true - defdelegate cast_input(value, constraints), to: Ash.Type.String + defdelegate cast_input(value, constraints), to: Ash.Type.CiString @impl true - defdelegate cast_stored(value, constraints), to: Ash.Type.String + defdelegate cast_stored(value, constraints), to: Ash.Type.CiString @impl true - defdelegate dump_to_native(value, constraints), to: Ash.Type.String + defdelegate dump_to_native(value, constraints), to: Ash.Type.CiString end diff --git a/lib/types/string_wrapper.ex b/lib/types/string_wrapper.ex new file mode 100644 index 00000000..82d067da --- /dev/null +++ b/lib/types/string_wrapper.ex @@ -0,0 +1,14 @@ +defmodule Ash.Type.StringWrapper do + @moduledoc false + use Ash.Type + + @impl true + def storage_type(_), do: :text + + @impl true + defdelegate cast_input(value, constraints), to: Ash.Type.String + @impl true + defdelegate cast_stored(value, constraints), to: Ash.Type.String + @impl true + defdelegate dump_to_native(value, constraints), to: Ash.Type.String +end