Disallow NULLs in deliveries

This commit is contained in:
rinpatch 2019-09-13 19:28:35 +03:00
parent 8900cb68ae
commit ac4a748fad
2 changed files with 3 additions and 2 deletions

View File

@ -23,6 +23,7 @@ defmodule Pleroma.Delivery do
def changeset(delivery, params \\ %{}) do
delivery
|> cast(params, [:user_id, :object_id])
|> validate_required([:user_id, :object_id])
|> foreign_key_constraint(:object_id)
|> foreign_key_constraint(:user_id)
|> unique_constraint(:user_id, name: :deliveries_user_id_object_id_index)

View File

@ -3,8 +3,8 @@ defmodule Pleroma.Repo.Migrations.CreateDeliveries do
def change do
create_if_not_exists table(:deliveries) do
add(:object_id, references(:objects, type: :id))
add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
add(:object_id, references(:objects, type: :id), null: false)
add(:user_id, references(:users, type: :uuid, on_delete: :delete_all), null: false)
end
create_if_not_exists index(:deliveries, :object_id, name: :deliveries_object_id)
create_if_not_exists(unique_index(:deliveries, [:user_id, :object_id]))