From dd8f957106e4e99ad6b50791714b7db14717f005 Mon Sep 17 00:00:00 2001 From: Sloane Date: Sun, 16 Jul 2023 11:36:19 -0400 Subject: [PATCH] fix: raise if primary_key: true and no prefix (#22) --- CHANGELOG.md | 4 ++++ lib/type_id/ecto.ex | 2 +- mix.exs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 824beba..03bbd7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.5.1 + +- raises if `prefix` is not given when `primary_key: true` + ## 0.5.0 - `Ecto.ParameterizedType` implementation traverses associations so prefixes only need to be defined on schema primary keys diff --git a/lib/type_id/ecto.ex b/lib/type_id/ecto.ex index a32f18f..7787395 100644 --- a/lib/type_id/ecto.ex +++ b/lib/type_id/ecto.ex @@ -86,7 +86,7 @@ if Code.ensure_loaded?(Ecto.ParameterizedType) do field = Keyword.fetch!(opts, :field) default_type = Application.get_env(:typeid_elixir, :default_type, :string) type = Keyword.get(opts, :type, default_type) - prefix = Keyword.get(opts, :prefix, "") + prefix = Keyword.get(opts, :prefix) if primary_key do unless prefix && prefix =~ ~r/^[a-z]{0,63}$/ do diff --git a/mix.exs b/mix.exs index ffad24c..8206100 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule TypeID.MixProject do use Mix.Project - @version "0.5.0" + @version "0.5.1" def project do [