summaryrefslogtreecommitdiff
path: root/priv/repo/migrations
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2021-02-03 14:23:23 +0000
committerfeld <feld@feld.me>2021-02-03 14:23:23 +0000
commit008499f65a33f5d42a98cc3719f6ab5e8def40d6 (patch)
tree1bcf258f38105267d4f655d8aed68d1ab502523f /priv/repo/migrations
parent39335d42513e47289fc825d04680531b84862686 (diff)
parentc3dd860a027ef1339285b5b62dc62e0b48bc6855 (diff)
downloadpleroma-008499f65a33f5d42a98cc3719f6ab5e8def40d6.tar.gz
pleroma-008499f65a33f5d42a98cc3719f6ab5e8def40d6.zip
Merge branch 'develop' into 'fix/2412-filters'
# Conflicts: # CHANGELOG.md
Diffstat (limited to 'priv/repo/migrations')
-rw-r--r--priv/repo/migrations/20210122151424_add_last_active_at_to_users.exs11
-rw-r--r--priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs29
2 files changed, 40 insertions, 0 deletions
diff --git a/priv/repo/migrations/20210122151424_add_last_active_at_to_users.exs b/priv/repo/migrations/20210122151424_add_last_active_at_to_users.exs
new file mode 100644
index 000000000..9671e495b
--- /dev/null
+++ b/priv/repo/migrations/20210122151424_add_last_active_at_to_users.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Repo.Migrations.AddLastActiveAtToUsers do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ add(:last_active_at, :naive_datetime)
+ end
+
+ create_if_not_exists(index(:users, [:last_active_at]))
+ end
+end
diff --git a/priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs b/priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs
new file mode 100644
index 000000000..309009205
--- /dev/null
+++ b/priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs
@@ -0,0 +1,29 @@
+defmodule Pleroma.Repo.Migrations.RemoveDuplicatesFromActivityExpirationQueue do
+ use Ecto.Migration
+
+ import Ecto.Query, only: [from: 2]
+
+ def up do
+ duplicate_ids =
+ from(j in Oban.Job,
+ where: j.queue == "activity_expiration",
+ where: j.worker == "Pleroma.Workers.PurgeExpiredActivity",
+ where: j.state == "scheduled",
+ select:
+ {fragment("(?)->>'activity_id'", j.args), fragment("array_agg(?)", j.id), count(j.id)},
+ group_by: fragment("(?)->>'activity_id'", j.args),
+ having: count(j.id) > 1
+ )
+ |> Pleroma.Repo.all()
+ |> Enum.map(fn {_, ids, _} ->
+ max_id = Enum.max(ids)
+ List.delete(ids, max_id)
+ end)
+ |> List.flatten()
+
+ from(j in Oban.Job, where: j.id in ^duplicate_ids)
+ |> Pleroma.Repo.delete_all()
+ end
+
+ def down, do: :noop
+end