summaryrefslogtreecommitdiff
path: root/priv/repo/migrations
diff options
context:
space:
mode:
Diffstat (limited to 'priv/repo/migrations')
-rw-r--r--priv/repo/migrations/20171212164525_fill_recipients_in_activities.exs4
-rw-r--r--priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs4
-rw-r--r--priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs40
-rw-r--r--priv/repo/migrations/20201005124600_quarantained_policy_string_to_tuple.exs61
-rw-r--r--priv/repo/migrations/20201005132900_transparency_exclusions_string_to_tuple.exs61
-rw-r--r--priv/repo/migrations/20210416051708_remove_mastofe_settings_from_users.exs9
-rw-r--r--priv/repo/migrations/20210717000000_add_poll_to_notifications_enum.exs49
-rw-r--r--priv/repo/migrations/20211125110126_force_pinned_objects_to_exist.exs11
8 files changed, 233 insertions, 6 deletions
diff --git a/priv/repo/migrations/20171212164525_fill_recipients_in_activities.exs b/priv/repo/migrations/20171212164525_fill_recipients_in_activities.exs
index 6dfa93716..77a09781c 100644
--- a/priv/repo/migrations/20171212164525_fill_recipients_in_activities.exs
+++ b/priv/repo/migrations/20171212164525_fill_recipients_in_activities.exs
@@ -14,9 +14,7 @@ defmodule Pleroma.Repo.Migrations.FillRecipientsInActivities do
max = min + 10_000
execute("""
- update activities set recipients = array(select jsonb_array_elements_text(data->'to')) where id > #{
- min
- } and id <= #{max};
+ update activities set recipients = array(select jsonb_array_elements_text(data->'to')) where id > #{min} and id <= #{max};
""")
|> IO.inspect()
end)
diff --git a/priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs b/priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs
index 2adc38186..81f941198 100644
--- a/priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs
+++ b/priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs
@@ -28,9 +28,7 @@ defmodule Pleroma.Repo.Migrations.InsertSkeletonsForDeletedUsers do
{:ok, %{rows: ap_ids}} =
Ecto.Adapters.SQL.query(
Repo,
- "select distinct unnest(nonexistent_locals.recipients) from activities, lateral (select array_agg(recipient) as recipients from unnest(activities.recipients) as recipient where recipient similar to '#{
- instance_uri
- }/users/[A-Za-z0-9]*' and not(recipient in (select ap_id from users))) nonexistent_locals;",
+ "select distinct unnest(nonexistent_locals.recipients) from activities, lateral (select array_agg(recipient) as recipients from unnest(activities.recipients) as recipient where recipient similar to '#{instance_uri}/users/[A-Za-z0-9]*' and not(recipient in (select ap_id from users))) nonexistent_locals;",
[],
timeout: :infinity
)
diff --git a/priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs b/priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs
new file mode 100644
index 000000000..77a4a7311
--- /dev/null
+++ b/priv/repo/migrations/20201005123100_simple_policy_string_to_tuple.exs
@@ -0,0 +1,40 @@
+defmodule Pleroma.Repo.Migrations.SimplePolicyStringToTuple do
+ use Ecto.Migration
+
+ alias Pleroma.ConfigDB
+
+ def up, do: ConfigDB.get_by_params(%{group: :pleroma, key: :mrf_simple}) |> update_to_tuples
+ def down, do: ConfigDB.get_by_params(%{group: :pleroma, key: :mrf_simple}) |> update_to_strings
+
+ defp update_to_tuples(%{value: value}) do
+ new_value =
+ value
+ |> Enum.map(fn {k, v} ->
+ {k,
+ Enum.map(v, fn
+ {instance, reason} -> {instance, reason}
+ instance -> {instance, ""}
+ end)}
+ end)
+
+ ConfigDB.update_or_create(%{group: :pleroma, key: :mrf_simple, value: new_value})
+ end
+
+ defp update_to_tuples(nil), do: {:ok, nil}
+
+ defp update_to_strings(%{value: value}) do
+ new_value =
+ value
+ |> Enum.map(fn {k, v} ->
+ {k,
+ Enum.map(v, fn
+ {instance, _} -> instance
+ instance -> instance
+ end)}
+ end)
+
+ ConfigDB.update_or_create(%{group: :pleroma, key: :mrf_simple, value: new_value})
+ end
+
+ defp update_to_strings(nil), do: {:ok, nil}
+end
diff --git a/priv/repo/migrations/20201005124600_quarantained_policy_string_to_tuple.exs b/priv/repo/migrations/20201005124600_quarantained_policy_string_to_tuple.exs
new file mode 100644
index 000000000..b924e4638
--- /dev/null
+++ b/priv/repo/migrations/20201005124600_quarantained_policy_string_to_tuple.exs
@@ -0,0 +1,61 @@
+defmodule Pleroma.Repo.Migrations.QuarantainedStringToTuple do
+ use Ecto.Migration
+
+ alias Pleroma.ConfigDB
+
+ def up,
+ do:
+ ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
+ |> update_quarantined_instances_to_tuples
+
+ def down,
+ do:
+ ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
+ |> update_quarantined_instances_to_strings
+
+ defp update_quarantined_instances_to_tuples(%{value: settings}) do
+ settings |> List.keyfind(:quarantined_instances, 0) |> update_to_tuples
+ end
+
+ defp update_quarantined_instances_to_tuples(nil), do: {:ok, nil}
+
+ defp update_to_tuples({:quarantined_instances, instance_list}) do
+ new_value =
+ instance_list
+ |> Enum.map(fn
+ {v, r} -> {v, r}
+ v -> {v, ""}
+ end)
+
+ ConfigDB.update_or_create(%{
+ group: :pleroma,
+ key: :instance,
+ value: [quarantined_instances: new_value]
+ })
+ end
+
+ defp update_to_tuples(nil), do: {:ok, nil}
+
+ defp update_quarantined_instances_to_strings(%{value: settings}) do
+ settings |> List.keyfind(:quarantined_instances, 0) |> update_to_strings
+ end
+
+ defp update_quarantined_instances_to_strings(nil), do: {:ok, nil}
+
+ defp update_to_strings({:quarantined_instances, instance_list}) do
+ new_value =
+ instance_list
+ |> Enum.map(fn
+ {v, _} -> v
+ v -> v
+ end)
+
+ ConfigDB.update_or_create(%{
+ group: :pleroma,
+ key: :instance,
+ value: [quarantined_instances: new_value]
+ })
+ end
+
+ defp update_to_strings(nil), do: {:ok, nil}
+end
diff --git a/priv/repo/migrations/20201005132900_transparency_exclusions_string_to_tuple.exs b/priv/repo/migrations/20201005132900_transparency_exclusions_string_to_tuple.exs
new file mode 100644
index 000000000..6516083a7
--- /dev/null
+++ b/priv/repo/migrations/20201005132900_transparency_exclusions_string_to_tuple.exs
@@ -0,0 +1,61 @@
+defmodule Pleroma.Repo.Migrations.TransparencyExclusionsStringToTuple do
+ use Ecto.Migration
+
+ alias Pleroma.ConfigDB
+
+ def up,
+ do:
+ ConfigDB.get_by_params(%{group: :pleroma, key: :mrf})
+ |> update_transparency_exclusions_instances_to_tuples
+
+ def down,
+ do:
+ ConfigDB.get_by_params(%{group: :pleroma, key: :mrf})
+ |> update_transparency_exclusions_instances_to_strings
+
+ defp update_transparency_exclusions_instances_to_tuples(%{value: settings}) do
+ settings |> List.keyfind(:transparency_exclusions, 0) |> update_to_tuples
+ end
+
+ defp update_transparency_exclusions_instances_to_tuples(nil), do: {:ok, nil}
+
+ defp update_to_tuples({:transparency_exclusions, instance_list}) do
+ new_value =
+ instance_list
+ |> Enum.map(fn
+ {v, r} -> {v, r}
+ v -> {v, ""}
+ end)
+
+ ConfigDB.update_or_create(%{
+ group: :pleroma,
+ key: :mrf,
+ value: [transparency_exclusions: new_value]
+ })
+ end
+
+ defp update_to_tuples(nil), do: {:ok, nil}
+
+ defp update_transparency_exclusions_instances_to_strings(%{value: settings}) do
+ settings |> List.keyfind(:transparency_exclusions, 0) |> update_to_strings
+ end
+
+ defp update_transparency_exclusions_instances_to_strings(nil), do: {:ok, nil}
+
+ defp update_to_strings({:transparency_exclusions, instance_list}) do
+ new_value =
+ instance_list
+ |> Enum.map(fn
+ {v, _} -> v
+ v -> v
+ end)
+
+ ConfigDB.update_or_create(%{
+ group: :pleroma,
+ key: :mrf,
+ value: [transparency_exclusions: new_value]
+ })
+ end
+
+ defp update_to_strings(nil), do: {:ok, nil}
+end
diff --git a/priv/repo/migrations/20210416051708_remove_mastofe_settings_from_users.exs b/priv/repo/migrations/20210416051708_remove_mastofe_settings_from_users.exs
new file mode 100644
index 000000000..a8d7306bd
--- /dev/null
+++ b/priv/repo/migrations/20210416051708_remove_mastofe_settings_from_users.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.RemoveMastofeSettingsFromUsers do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ remove_if_exists(:mastofe_settings, :map)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20210717000000_add_poll_to_notifications_enum.exs b/priv/repo/migrations/20210717000000_add_poll_to_notifications_enum.exs
new file mode 100644
index 000000000..9abf40b3d
--- /dev/null
+++ b/priv/repo/migrations/20210717000000_add_poll_to_notifications_enum.exs
@@ -0,0 +1,49 @@
+defmodule Pleroma.Repo.Migrations.AddPollToNotificationsEnum do
+ use Ecto.Migration
+
+ @disable_ddl_transaction true
+
+ def up do
+ """
+ alter type notification_type add value 'poll'
+ """
+ |> execute()
+ end
+
+ def down do
+ alter table(:notifications) do
+ modify(:type, :string)
+ end
+
+ """
+ delete from notifications where type = 'poll'
+ """
+ |> execute()
+
+ """
+ drop type if exists notification_type
+ """
+ |> execute()
+
+ """
+ create type notification_type as enum (
+ 'follow',
+ 'follow_request',
+ 'mention',
+ 'move',
+ 'pleroma:emoji_reaction',
+ 'pleroma:chat_mention',
+ 'reblog',
+ 'favourite',
+ 'pleroma:report'
+ )
+ """
+ |> execute()
+
+ """
+ alter table notifications
+ alter column type type notification_type using (type::notification_type)
+ """
+ |> execute()
+ end
+end
diff --git a/priv/repo/migrations/20211125110126_force_pinned_objects_to_exist.exs b/priv/repo/migrations/20211125110126_force_pinned_objects_to_exist.exs
new file mode 100644
index 000000000..1fe9271f0
--- /dev/null
+++ b/priv/repo/migrations/20211125110126_force_pinned_objects_to_exist.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Repo.Migrations.ForcePinnedObjectsToExist do
+ use Ecto.Migration
+
+ def change do
+ execute("UPDATE users SET pinned_objects = '{}' WHERE pinned_objects IS NULL")
+
+ alter table("users") do
+ modify(:pinned_objects, :map, null: false, default: %{})
+ end
+ end
+end