From 500034ef771c5c40fb7f8708e4193b7eb534d7f9 Mon Sep 17 00:00:00 2001 From: Daniel Berkompas Date: Sat, 6 Apr 2024 08:24:09 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`Migrator`=20when=20schema?= =?UTF-8?q?=20contains=20`Ecto.Enum`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #46. The migrator raised the error in #46 because it didn't expect the `Ecto.Enum` field type when checking which fields contain Cloak types. --- lib/cloak_ecto/migrator.ex | 4 ++++ test/support/migrations/20180321184642_create_users.exs | 1 + test/support/user.ex | 2 ++ 3 files changed, 7 insertions(+) diff --git a/lib/cloak_ecto/migrator.ex b/lib/cloak_ecto/migrator.ex index 0ab5af7..77fea4a 100644 --- a/lib/cloak_ecto/migrator.ex +++ b/lib/cloak_ecto/migrator.ex @@ -73,6 +73,10 @@ defmodule Cloak.Ecto.Migrator do false end + defp cloak_field?({_field, {:parameterized, Ecto.Enum, _opts}}) do + false + end + defp cloak_field?({field, {kind, inner_type}}) when kind in [:array, :map] do cloak_field?({field, inner_type}) end diff --git a/test/support/migrations/20180321184642_create_users.exs b/test/support/migrations/20180321184642_create_users.exs index 8defe86..8a231d8 100644 --- a/test/support/migrations/20180321184642_create_users.exs +++ b/test/support/migrations/20180321184642_create_users.exs @@ -6,6 +6,7 @@ defmodule Cloak.Ecto.TestRepo.Migrations.CreateUsers do add(:name, :string) add(:email, :binary) add(:email_hash, :binary) + add(:status, :string) timestamps(type: :utc_datetime) end diff --git a/test/support/user.ex b/test/support/user.ex index 8c41b12..5a3086b 100644 --- a/test/support/user.ex +++ b/test/support/user.ex @@ -5,6 +5,8 @@ defmodule Cloak.Ecto.TestUser do field(:name, :string) field(:email, Cloak.Ecto.Encrypted.Binary) field(:email_hash, Cloak.Ecto.Hashed.HMAC) + field(:status, Ecto.Enum, values: [active: "active", disabled: "disabled"]) + timestamps(type: :utc_datetime) end end