summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20200808173046_only_expire_creates.exs
blob: 550cec6d86b4a8ef1b9419f52d1f0861fa62e3e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Pleroma: A lightweight social networking server
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Repo.Migrations.OnlyExpireCreates do
  use Ecto.Migration

  def up do
    statement = """
    DELETE FROM
      activity_expirations a_exp USING activities a, objects o
    WHERE
      a_exp.activity_id = a.id AND (o.data->>'id') = COALESCE(a.data->'object'->>'id', a.data->>'object')
      AND (a.data->>'type' != 'Create' OR o.data->>'type' != 'Note');
    """

    execute(statement)
  end

  def down do
    :ok
  end
end