From: Ivan Tashkinov Date: Mon, 18 Mar 2019 17:31:24 +0000 (+0300) Subject: [#923] Registration validations & unique index on [:user_id, :provider]. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=40e9a04c31a9965dee92cb8f07ed6db28f8ccd75;p=akkoma [#923] Registration validations & unique index on [:user_id, :provider]. --- diff --git a/lib/pleroma/registration.ex b/lib/pleroma/registration.ex index 1bd91a316..773e25fa6 100644 --- a/lib/pleroma/registration.ex +++ b/lib/pleroma/registration.ex @@ -23,6 +23,7 @@ defmodule Pleroma.Registration do def changeset(registration, params \\ %{}) do registration |> cast(params, [:user_id, :provider, :uid, :info]) + |> validate_required([:provider, :uid]) |> foreign_key_constraint(:user_id) |> unique_constraint(:uid, name: :registrations_provider_uid_index) end diff --git a/priv/repo/migrations/20190315101315_create_registrations.exs b/priv/repo/migrations/20190315101315_create_registrations.exs index dac86b780..c566912f5 100644 --- a/priv/repo/migrations/20190315101315_create_registrations.exs +++ b/priv/repo/migrations/20190315101315_create_registrations.exs @@ -12,5 +12,6 @@ defmodule Pleroma.Repo.Migrations.CreateRegistrations do end create unique_index(:registrations, [:provider, :uid]) + create unique_index(:registrations, [:user_id, :provider]) end end