Represent rule IDs as strings

This commit is contained in:
Alex Gleason 2022-05-02 14:16:03 -05:00
parent 5e4d87541c
commit 5b97fcb566
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 25 additions and 0 deletions

View file

@ -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

View file

@ -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)