Represent rule IDs as strings
This commit is contained in:
parent
5e4d87541c
commit
5b97fcb566
2 changed files with 25 additions and 0 deletions
23
lib/pleroma/ecto_type/string_id.ex
Normal file
23
lib/pleroma/ecto_type/string_id.ex
Normal 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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue