diff --git a/lib/pleroma/ecto_type/string_id.ex b/lib/pleroma/ecto_type/string_id.ex new file mode 100644 index 0000000000..a3df5c07e3 --- /dev/null +++ b/lib/pleroma/ecto_type/string_id.ex @@ -0,0 +1,23 @@ +defmodule Pleroma.EctoType.StringId do + @moduledoc """ + Stores the value as a number in the database, but represents it as a string. + """ + use Ecto.Type + + def type, do: :id + + def cast(value) do + {:ok, to_string(value)} + end + + def load(value) do + {:ok, to_string(value)} + end + + def dump(value) do + case Integer.parse(value) do + {n, _} -> {:ok, n} + _ -> {:error, value} + end + end +end diff --git a/lib/pleroma/rule.ex b/lib/pleroma/rule.ex index b1db1dc0c5..067d071112 100644 --- a/lib/pleroma/rule.ex +++ b/lib/pleroma/rule.ex @@ -11,6 +11,8 @@ defmodule Pleroma.Rule do alias Pleroma.Repo alias Pleroma.Rule + @primary_key {:id, Pleroma.EctoType.StringId, autogenerate: true} + schema "rules" do field(:priority, :integer, default: 0) field(:text, :string)