Ensure delete cascades on activity delete

This commit is contained in:
FloatingGhost 2022-11-29 11:44:42 +00:00
parent 0cfd5b4e89
commit f69b4e8573
6 changed files with 56 additions and 0 deletions

View File

@ -10,6 +10,7 @@ defmodule Pleroma.Object do
alias Pleroma.Activity
alias Pleroma.Config
alias Pleroma.Delivery
alias Pleroma.Hashtag
alias Pleroma.Object
alias Pleroma.Object.Fetcher
@ -30,6 +31,7 @@ defmodule Pleroma.Object do
field(:data, :map)
many_to_many(:hashtags, Hashtag, join_through: "hashtags_objects", on_replace: :delete)
has_many(:deliveries, Delivery, on_delete: :delete_all)
timestamps()
end

View File

@ -0,0 +1,16 @@
defmodule Pleroma.Repo.Migrations.DeleteDeliveriesOnObjectDelete do
use Ecto.Migration
def up do
drop constraint(:deliveries, "deliveries_object_id_fkey")
alter table(:deliveries) do
modify :object_id, references(:objects, type: :id, on_delete: :delete_all), null: false
end
end
def down do
drop constraint(:deliveries, "deliveries_object_id_fkey")
alter table(:deliveries) do
modify :object_id, references(:objects, type: :id), null: false
end
end
end

View File

@ -0,0 +1,7 @@
defmodule Pleroma.Repo.Migrations.AddNotificationActivityIdIndex do
use Ecto.Migration
def change do
create(index(:notifications, [:activity_id]))
end
end

View File

@ -0,0 +1,7 @@
defmodule Pleroma.Repo.Migrations.AddBookmarksActivityIdIndex do
use Ecto.Migration
def change do
create(index(:bookmarks, [:activity_id]))
end
end

View File

@ -0,0 +1,7 @@
defmodule Pleroma.Repo.Migrations.AddReportNotesActivityIdIndex do
use Ecto.Migration
def change do
create(index(:report_notes, [:activity_id]))
end
end

View File

@ -0,0 +1,17 @@
defmodule Pleroma.Repo.Migrations.AddCascadeToReportNotesOnActivityDelete do
use Ecto.Migration
def up do
drop constraint(:report_notes, "report_notes_activity_id_fkey")
alter table(:report_notes) do
modify :activity_id, references(:activities, type: :uuid, on_delete: :delete_all)
end
end
def down do
drop constraint(:report_notes, "report_notes_activity_id_fkey")
alter table(:report_notes) do
modify :activity_id, references(:activities, type: :uuid)
end
end
end