aboutsummaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20200802170532_fix_legacy_tags.exs37
-rw-r--r--priv/repo/migrations/20200804180322_remove_nonlocal_expirations.exs19
-rw-r--r--priv/repo/migrations/20200804183107_add_unique_index_to_app_client_id.exs7
3 files changed, 63 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200802170532_fix_legacy_tags.exs b/priv/repo/migrations/20200802170532_fix_legacy_tags.exs
new file mode 100644
index 000000000..f7274b44e
--- /dev/null
+++ b/priv/repo/migrations/20200802170532_fix_legacy_tags.exs
@@ -0,0 +1,37 @@
+# Fix legacy tags set by AdminFE that don't align with TagPolicy MRF
+
+defmodule Pleroma.Repo.Migrations.FixLegacyTags do
+ use Ecto.Migration
+ alias Pleroma.Repo
+ alias Pleroma.User
+ import Ecto.Query
+
+ @old_new_map %{
+ "force_nsfw" => "mrf_tag:media-force-nsfw",
+ "strip_media" => "mrf_tag:media-strip",
+ "force_unlisted" => "mrf_tag:force-unlisted",
+ "sandbox" => "mrf_tag:sandbox",
+ "disable_remote_subscription" => "mrf_tag:disable-remote-subscription",
+ "disable_any_subscription" => "mrf_tag:disable-any-subscription"
+ }
+
+ def change do
+ legacy_tags = Map.keys(@old_new_map)
+
+ from(u in User, where: fragment("? && ?", u.tags, ^legacy_tags))
+ |> Repo.all()
+ |> Enum.each(fn user ->
+ fix_tags_changeset(user)
+ |> Repo.update()
+ end)
+ end
+
+ defp fix_tags_changeset(%User{tags: tags} = user) do
+ new_tags =
+ Enum.map(tags, fn tag ->
+ Map.get(@old_new_map, tag, tag)
+ end)
+
+ Ecto.Changeset.change(user, tags: new_tags)
+ end
+end
diff --git a/priv/repo/migrations/20200804180322_remove_nonlocal_expirations.exs b/priv/repo/migrations/20200804180322_remove_nonlocal_expirations.exs
new file mode 100644
index 000000000..389935f0d
--- /dev/null
+++ b/priv/repo/migrations/20200804180322_remove_nonlocal_expirations.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.RemoveNonlocalExpirations do
+ use Ecto.Migration
+
+ def up do
+ statement = """
+ DELETE FROM
+ activity_expirations A USING activities B
+ WHERE
+ A.activity_id = B.id
+ AND B.local = false;
+ """
+
+ execute(statement)
+ end
+
+ def down do
+ :ok
+ end
+end
diff --git a/priv/repo/migrations/20200804183107_add_unique_index_to_app_client_id.exs b/priv/repo/migrations/20200804183107_add_unique_index_to_app_client_id.exs
new file mode 100644
index 000000000..83de18096
--- /dev/null
+++ b/priv/repo/migrations/20200804183107_add_unique_index_to_app_client_id.exs
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.AddUniqueIndexToAppClientId do
+ use Ecto.Migration
+
+ def change do
+ create(unique_index(:apps, [:client_id]))
+ end
+end