summaryrefslogtreecommitdiff
path: root/priv/repo/migrations
diff options
context:
space:
mode:
Diffstat (limited to 'priv/repo/migrations')
-rw-r--r--priv/repo/migrations/20200712234852_add_approval_fields_to_users.exs10
-rw-r--r--priv/repo/migrations/20200802170532_fix_legacy_tags.exs40
-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
-rw-r--r--priv/repo/migrations/20200808173046_only_expire_creates.exs19
-rw-r--r--priv/repo/migrations/20200811125613_set_defaults_to_user_approval_pending.exs15
-rw-r--r--priv/repo/migrations/20200811143147_ap_id_not_null.exs19
-rw-r--r--priv/repo/migrations/20200817120935_add_invisible_index_to_users.exs7
-rw-r--r--priv/repo/migrations/20200824115541_rename_activity_expiration_setting.exs13
-rw-r--r--priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs28
-rw-r--r--priv/repo/migrations/20200825093037_drop_activity_expirations_table.exs7
-rw-r--r--priv/repo/migrations/20200831114918_remove_unread_conversation_count_from_user.exs38
-rw-r--r--priv/repo/migrations/20200831115854_add_unread_index_to_conversation_participation.exs12
-rw-r--r--priv/repo/migrations/20200831142509_chat_constraints.exs22
-rw-r--r--priv/repo/migrations/20200831152600_add_pleroma_report_to_enum_for_notifications.exs48
-rw-r--r--priv/repo/migrations/20200831192323_create_backups.exs17
-rw-r--r--priv/repo/migrations/20200901061256_ensure_bio_is_string.exs7
-rw-r--r--priv/repo/migrations/20200901061637_bio_set_not_null.exs10
-rw-r--r--priv/repo/migrations/20200905082737_rename_await_up_timeout_in_connections_pool.exs13
-rw-r--r--priv/repo/migrations/20200905091427_rename_timeout_in_pools.exs19
-rw-r--r--priv/repo/migrations/20200906072147_remove_cron_stats_worker_from_oban_config.exs19
-rw-r--r--priv/repo/migrations/20200907084956_remove_cron_clear_oauth_token_worker_from_oban_config.exs19
-rw-r--r--priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs38
-rw-r--r--priv/repo/migrations/20200910113106_remove_managed_config_from_db.exs27
-rw-r--r--priv/repo/migrations/20200911055909_remove_cron_jobs.exs20
-rw-r--r--priv/repo/migrations/20200914105638_delete_notification_without_activity.exs30
-rw-r--r--priv/repo/migrations/20200914105800_add_notification_constraints.exs23
-rw-r--r--priv/repo/migrations/20200915095704_remove_background_jobs.exs22
-rw-r--r--priv/repo/migrations/20200919182636_remoteip_plug_rename.exs19
-rw-r--r--priv/repo/migrations/20200925065249_make_user_ids_ci.exs9
-rw-r--r--priv/repo/migrations/20200928145912_revert_citext_change.exs11
-rw-r--r--priv/repo/migrations/20200930082320_user_ur_is_index_part_three.exs8
-rw-r--r--priv/repo/migrations/20201013141127_refactor_locked_user_field.exs15
-rw-r--r--priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs15
-rw-r--r--priv/repo/migrations/20201113060459_remove_purge_expired_activity_worker_from_oban_config.exs19
35 files changed, 664 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200712234852_add_approval_fields_to_users.exs b/priv/repo/migrations/20200712234852_add_approval_fields_to_users.exs
new file mode 100644
index 000000000..43f741a5b
--- /dev/null
+++ b/priv/repo/migrations/20200712234852_add_approval_fields_to_users.exs
@@ -0,0 +1,10 @@
+defmodule Pleroma.Repo.Migrations.AddApprovalFieldsToUsers do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ add(:approval_pending, :boolean)
+ add(:registration_reason, :text)
+ end
+ end
+end
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..ca82fac42
--- /dev/null
+++ b/priv/repo/migrations/20200802170532_fix_legacy_tags.exs
@@ -0,0 +1,40 @@
+# 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),
+ select: struct(u, [:tags, :id])
+ )
+ |> Repo.chunk_stream(100)
+ |> 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
diff --git a/priv/repo/migrations/20200808173046_only_expire_creates.exs b/priv/repo/migrations/20200808173046_only_expire_creates.exs
new file mode 100644
index 000000000..9df52956f
--- /dev/null
+++ b/priv/repo/migrations/20200808173046_only_expire_creates.exs
@@ -0,0 +1,19 @@
+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
diff --git a/priv/repo/migrations/20200811125613_set_defaults_to_user_approval_pending.exs b/priv/repo/migrations/20200811125613_set_defaults_to_user_approval_pending.exs
new file mode 100644
index 000000000..eec7da03f
--- /dev/null
+++ b/priv/repo/migrations/20200811125613_set_defaults_to_user_approval_pending.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.SetDefaultsToUserApprovalPending do
+ use Ecto.Migration
+
+ def up do
+ execute("UPDATE users SET approval_pending = false WHERE approval_pending IS NULL")
+
+ alter table(:users) do
+ modify(:approval_pending, :boolean, default: false, null: false)
+ end
+ end
+
+ def down do
+ :ok
+ end
+end
diff --git a/priv/repo/migrations/20200811143147_ap_id_not_null.exs b/priv/repo/migrations/20200811143147_ap_id_not_null.exs
new file mode 100644
index 000000000..df649c7ca
--- /dev/null
+++ b/priv/repo/migrations/20200811143147_ap_id_not_null.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.ApIdNotNull do
+ use Ecto.Migration
+
+ require Logger
+
+ def up do
+ Logger.warn(
+ "If this migration fails please open an issue at https://git.pleroma.social/pleroma/pleroma/-/issues/new \n"
+ )
+
+ alter table(:users) do
+ modify(:ap_id, :string, null: false)
+ end
+ end
+
+ def down do
+ :ok
+ end
+end
diff --git a/priv/repo/migrations/20200817120935_add_invisible_index_to_users.exs b/priv/repo/migrations/20200817120935_add_invisible_index_to_users.exs
new file mode 100644
index 000000000..2417d366e
--- /dev/null
+++ b/priv/repo/migrations/20200817120935_add_invisible_index_to_users.exs
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.AddInvisibleIndexToUsers do
+ use Ecto.Migration
+
+ def change do
+ create(index(:users, [:invisible]))
+ end
+end
diff --git a/priv/repo/migrations/20200824115541_rename_activity_expiration_setting.exs b/priv/repo/migrations/20200824115541_rename_activity_expiration_setting.exs
new file mode 100644
index 000000000..241882ef6
--- /dev/null
+++ b/priv/repo/migrations/20200824115541_rename_activity_expiration_setting.exs
@@ -0,0 +1,13 @@
+defmodule Pleroma.Repo.Migrations.RenameActivityExpirationSetting do
+ use Ecto.Migration
+
+ def change do
+ config = Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.ActivityExpiration})
+
+ if config do
+ config
+ |> Ecto.Changeset.change(key: Pleroma.Workers.PurgeExpiredActivity)
+ |> Pleroma.Repo.update()
+ end
+ end
+end
diff --git a/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs b/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs
new file mode 100644
index 000000000..a703af83f
--- /dev/null
+++ b/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs
@@ -0,0 +1,28 @@
+defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do
+ use Ecto.Migration
+
+ import Ecto.Query, only: [from: 2]
+
+ def change do
+ Pleroma.Config.Oban.warn()
+
+ Supervisor.start_link([{Oban, Pleroma.Config.get(Oban)}],
+ strategy: :one_for_one,
+ name: Pleroma.Supervisor
+ )
+
+ from(e in "activity_expirations",
+ select: %{id: e.id, activity_id: e.activity_id, scheduled_at: e.scheduled_at}
+ )
+ |> Pleroma.Repo.stream()
+ |> Stream.each(fn expiration ->
+ with {:ok, expires_at} <- DateTime.from_naive(expiration.scheduled_at, "Etc/UTC") do
+ Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
+ activity_id: FlakeId.to_string(expiration.activity_id),
+ expires_at: expires_at
+ })
+ end
+ end)
+ |> Stream.run()
+ end
+end
diff --git a/priv/repo/migrations/20200825093037_drop_activity_expirations_table.exs b/priv/repo/migrations/20200825093037_drop_activity_expirations_table.exs
new file mode 100644
index 000000000..11c461427
--- /dev/null
+++ b/priv/repo/migrations/20200825093037_drop_activity_expirations_table.exs
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.DropActivityExpirationsTable do
+ use Ecto.Migration
+
+ def change do
+ drop(table("activity_expirations"))
+ end
+end
diff --git a/priv/repo/migrations/20200831114918_remove_unread_conversation_count_from_user.exs b/priv/repo/migrations/20200831114918_remove_unread_conversation_count_from_user.exs
new file mode 100644
index 000000000..b7bdb9166
--- /dev/null
+++ b/priv/repo/migrations/20200831114918_remove_unread_conversation_count_from_user.exs
@@ -0,0 +1,38 @@
+defmodule Pleroma.Repo.Migrations.RemoveUnreadConversationCountFromUser do
+ use Ecto.Migration
+ import Ecto.Query
+ alias Pleroma.Repo
+
+ def up do
+ alter table(:users) do
+ remove_if_exists(:unread_conversation_count, :integer)
+ end
+ end
+
+ def down do
+ alter table(:users) do
+ add_if_not_exists(:unread_conversation_count, :integer, default: 0)
+ end
+
+ flush()
+ recalc_unread_conversation_count()
+ end
+
+ defp recalc_unread_conversation_count do
+ participations_subquery =
+ from(
+ p in "conversation_participations",
+ where: p.read == false,
+ group_by: p.user_id,
+ select: %{user_id: p.user_id, unread_conversation_count: count(p.id)}
+ )
+
+ from(
+ u in "users",
+ join: p in subquery(participations_subquery),
+ on: p.user_id == u.id,
+ update: [set: [unread_conversation_count: p.unread_conversation_count]]
+ )
+ |> Repo.update_all([])
+ end
+end
diff --git a/priv/repo/migrations/20200831115854_add_unread_index_to_conversation_participation.exs b/priv/repo/migrations/20200831115854_add_unread_index_to_conversation_participation.exs
new file mode 100644
index 000000000..68771c655
--- /dev/null
+++ b/priv/repo/migrations/20200831115854_add_unread_index_to_conversation_participation.exs
@@ -0,0 +1,12 @@
+defmodule Pleroma.Repo.Migrations.AddUnreadIndexToConversationParticipation do
+ use Ecto.Migration
+
+ def change do
+ create(
+ index(:conversation_participations, [:user_id],
+ where: "read = false",
+ name: "unread_conversation_participation_count_index"
+ )
+ )
+ end
+end
diff --git a/priv/repo/migrations/20200831142509_chat_constraints.exs b/priv/repo/migrations/20200831142509_chat_constraints.exs
new file mode 100644
index 000000000..868a40a45
--- /dev/null
+++ b/priv/repo/migrations/20200831142509_chat_constraints.exs
@@ -0,0 +1,22 @@
+defmodule Pleroma.Repo.Migrations.ChatConstraints do
+ use Ecto.Migration
+
+ def change do
+ remove_orphans = """
+ delete from chats where not exists(select id from users where ap_id = chats.recipient);
+ """
+
+ execute(remove_orphans)
+
+ drop(constraint(:chats, "chats_user_id_fkey"))
+
+ alter table(:chats) do
+ modify(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
+
+ modify(
+ :recipient,
+ references(:users, column: :ap_id, type: :string, on_delete: :delete_all)
+ )
+ end
+ end
+end
diff --git a/priv/repo/migrations/20200831152600_add_pleroma_report_to_enum_for_notifications.exs b/priv/repo/migrations/20200831152600_add_pleroma_report_to_enum_for_notifications.exs
new file mode 100644
index 000000000..01fb90459
--- /dev/null
+++ b/priv/repo/migrations/20200831152600_add_pleroma_report_to_enum_for_notifications.exs
@@ -0,0 +1,48 @@
+defmodule Pleroma.Repo.Migrations.AddPleromaReportTypeToEnumForNotifications do
+ use Ecto.Migration
+
+ @disable_ddl_transaction true
+
+ def up do
+ """
+ alter type notification_type add value 'pleroma:report'
+ """
+ |> execute()
+ end
+
+ def down do
+ alter table(:notifications) do
+ modify(:type, :string)
+ end
+
+ """
+ delete from notifications where type = 'pleroma:report'
+ """
+ |> 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'
+ )
+ """
+ |> execute()
+
+ """
+ alter table notifications
+ alter column type type notification_type using (type::notification_type)
+ """
+ |> execute()
+ end
+end
diff --git a/priv/repo/migrations/20200831192323_create_backups.exs b/priv/repo/migrations/20200831192323_create_backups.exs
new file mode 100644
index 000000000..3ac5889e2
--- /dev/null
+++ b/priv/repo/migrations/20200831192323_create_backups.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.CreateBackups do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:backups) do
+ add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
+ add(:file_name, :string, null: false)
+ add(:content_type, :string, null: false)
+ add(:processed, :boolean, null: false, default: false)
+ add(:file_size, :bigint)
+
+ timestamps()
+ end
+
+ create_if_not_exists(index(:backups, [:user_id]))
+ end
+end
diff --git a/priv/repo/migrations/20200901061256_ensure_bio_is_string.exs b/priv/repo/migrations/20200901061256_ensure_bio_is_string.exs
new file mode 100644
index 000000000..0e3bb3c81
--- /dev/null
+++ b/priv/repo/migrations/20200901061256_ensure_bio_is_string.exs
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.EnsureBioIsString do
+ use Ecto.Migration
+
+ def change do
+ execute("update users set bio = '' where bio is null", "")
+ end
+end
diff --git a/priv/repo/migrations/20200901061637_bio_set_not_null.exs b/priv/repo/migrations/20200901061637_bio_set_not_null.exs
new file mode 100644
index 000000000..e3a67d4e7
--- /dev/null
+++ b/priv/repo/migrations/20200901061637_bio_set_not_null.exs
@@ -0,0 +1,10 @@
+defmodule Pleroma.Repo.Migrations.BioSetNotNull do
+ use Ecto.Migration
+
+ def change do
+ execute(
+ "alter table users alter column bio set not null",
+ "alter table users alter column bio drop not null"
+ )
+ end
+end
diff --git a/priv/repo/migrations/20200905082737_rename_await_up_timeout_in_connections_pool.exs b/priv/repo/migrations/20200905082737_rename_await_up_timeout_in_connections_pool.exs
new file mode 100644
index 000000000..22c40663c
--- /dev/null
+++ b/priv/repo/migrations/20200905082737_rename_await_up_timeout_in_connections_pool.exs
@@ -0,0 +1,13 @@
+defmodule Pleroma.Repo.Migrations.RenameAwaitUpTimeoutInConnectionsPool do
+ use Ecto.Migration
+
+ def change do
+ with %Pleroma.ConfigDB{} = config <-
+ Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: :connections_pool}),
+ {timeout, value} when is_integer(timeout) <- Keyword.pop(config.value, :await_up_timeout) do
+ config
+ |> Ecto.Changeset.change(value: Keyword.put(value, :connect_timeout, timeout))
+ |> Pleroma.Repo.update()
+ end
+ end
+end
diff --git a/priv/repo/migrations/20200905091427_rename_timeout_in_pools.exs b/priv/repo/migrations/20200905091427_rename_timeout_in_pools.exs
new file mode 100644
index 000000000..bb2f50ecc
--- /dev/null
+++ b/priv/repo/migrations/20200905091427_rename_timeout_in_pools.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.RenameTimeoutInPools do
+ use Ecto.Migration
+
+ def change do
+ with %Pleroma.ConfigDB{} = config <-
+ Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: :pools}) do
+ updated_value =
+ Enum.map(config.value, fn {pool, pool_value} ->
+ with {timeout, value} when is_integer(timeout) <- Keyword.pop(pool_value, :timeout) do
+ {pool, Keyword.put(value, :recv_timeout, timeout)}
+ end
+ end)
+
+ config
+ |> Ecto.Changeset.change(value: updated_value)
+ |> Pleroma.Repo.update()
+ end
+ end
+end
diff --git a/priv/repo/migrations/20200906072147_remove_cron_stats_worker_from_oban_config.exs b/priv/repo/migrations/20200906072147_remove_cron_stats_worker_from_oban_config.exs
new file mode 100644
index 000000000..022f21dc7
--- /dev/null
+++ b/priv/repo/migrations/20200906072147_remove_cron_stats_worker_from_oban_config.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.RemoveCronStatsWorkerFromObanConfig do
+ use Ecto.Migration
+
+ def change do
+ with %Pleroma.ConfigDB{} = config <-
+ Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Oban}),
+ crontab when is_list(crontab) <- config.value[:crontab],
+ index when is_integer(index) <-
+ Enum.find_index(crontab, fn {_, worker} ->
+ worker == Pleroma.Workers.Cron.StatsWorker
+ end) do
+ updated_value = Keyword.put(config.value, :crontab, List.delete_at(crontab, index))
+
+ config
+ |> Ecto.Changeset.change(value: updated_value)
+ |> Pleroma.Repo.update()
+ end
+ end
+end
diff --git a/priv/repo/migrations/20200907084956_remove_cron_clear_oauth_token_worker_from_oban_config.exs b/priv/repo/migrations/20200907084956_remove_cron_clear_oauth_token_worker_from_oban_config.exs
new file mode 100644
index 000000000..b5a0a0ff6
--- /dev/null
+++ b/priv/repo/migrations/20200907084956_remove_cron_clear_oauth_token_worker_from_oban_config.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.RemoveCronClearOauthTokenWorkerFromObanConfig do
+ use Ecto.Migration
+
+ def change do
+ with %Pleroma.ConfigDB{} = config <-
+ Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Oban}),
+ crontab when is_list(crontab) <- config.value[:crontab],
+ index when is_integer(index) <-
+ Enum.find_index(crontab, fn {_, worker} ->
+ worker == Pleroma.Workers.Cron.ClearOauthTokenWorker
+ end) do
+ updated_value = Keyword.put(config.value, :crontab, List.delete_at(crontab, index))
+
+ config
+ |> Ecto.Changeset.change(value: updated_value)
+ |> Pleroma.Repo.update()
+ end
+ end
+end
diff --git a/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs b/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs
new file mode 100644
index 000000000..9e49ddacb
--- /dev/null
+++ b/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs
@@ -0,0 +1,38 @@
+defmodule Pleroma.Repo.Migrations.MoveTokensExpirationIntoOban do
+ use Ecto.Migration
+
+ import Ecto.Query, only: [from: 2]
+
+ def change do
+ Pleroma.Config.Oban.warn()
+
+ Supervisor.start_link([{Oban, Pleroma.Config.get(Oban)}],
+ strategy: :one_for_one,
+ name: Pleroma.Supervisor
+ )
+
+ if Pleroma.Config.get([:oauth2, :clean_expired_tokens]) do
+ from(t in Pleroma.Web.OAuth.Token, where: t.valid_until > ^NaiveDateTime.utc_now())
+ |> Pleroma.Repo.stream()
+ |> Stream.each(fn token ->
+ Pleroma.Workers.PurgeExpiredToken.enqueue(%{
+ token_id: token.id,
+ valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
+ mod: Pleroma.Web.OAuth.Token
+ })
+ end)
+ |> Stream.run()
+ end
+
+ from(t in Pleroma.MFA.Token, where: t.valid_until > ^NaiveDateTime.utc_now())
+ |> Pleroma.Repo.stream()
+ |> Stream.each(fn token ->
+ Pleroma.Workers.PurgeExpiredToken.enqueue(%{
+ token_id: token.id,
+ valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
+ mod: Pleroma.MFA.Token
+ })
+ end)
+ |> Stream.run()
+ end
+end
diff --git a/priv/repo/migrations/20200910113106_remove_managed_config_from_db.exs b/priv/repo/migrations/20200910113106_remove_managed_config_from_db.exs
new file mode 100644
index 000000000..e27a9ae48
--- /dev/null
+++ b/priv/repo/migrations/20200910113106_remove_managed_config_from_db.exs
@@ -0,0 +1,27 @@
+defmodule Pleroma.Repo.Migrations.RemoveManagedConfigFromDb do
+ use Ecto.Migration
+ import Ecto.Query
+ alias Pleroma.ConfigDB
+ alias Pleroma.Repo
+
+ def up do
+ config_entry =
+ from(c in ConfigDB,
+ select: [:id, :value],
+ where: c.group == ^:pleroma and c.key == ^:instance
+ )
+ |> Repo.one()
+
+ if config_entry do
+ {_, value} = Keyword.pop(config_entry.value, :managed_config)
+
+ config_entry
+ |> Ecto.Changeset.change(value: value)
+ |> Repo.update()
+ end
+ end
+
+ def down do
+ :ok
+ end
+end
diff --git a/priv/repo/migrations/20200911055909_remove_cron_jobs.exs b/priv/repo/migrations/20200911055909_remove_cron_jobs.exs
new file mode 100644
index 000000000..33897d128
--- /dev/null
+++ b/priv/repo/migrations/20200911055909_remove_cron_jobs.exs
@@ -0,0 +1,20 @@
+defmodule Pleroma.Repo.Migrations.RemoveCronJobs do
+ use Ecto.Migration
+
+ import Ecto.Query, only: [from: 2]
+
+ def up do
+ from(j in "oban_jobs",
+ where:
+ j.worker in ^[
+ "Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker",
+ "Pleroma.Workers.Cron.StatsWorker",
+ "Pleroma.Workers.Cron.ClearOauthTokenWorker"
+ ],
+ select: [:id]
+ )
+ |> Pleroma.Repo.delete_all()
+ end
+
+ def down, do: :ok
+end
diff --git a/priv/repo/migrations/20200914105638_delete_notification_without_activity.exs b/priv/repo/migrations/20200914105638_delete_notification_without_activity.exs
new file mode 100644
index 000000000..9333fc5a1
--- /dev/null
+++ b/priv/repo/migrations/20200914105638_delete_notification_without_activity.exs
@@ -0,0 +1,30 @@
+defmodule Pleroma.Repo.Migrations.DeleteNotificationWithoutActivity do
+ use Ecto.Migration
+
+ import Ecto.Query
+ alias Pleroma.Repo
+
+ def up do
+ from(
+ q in Pleroma.Notification,
+ left_join: c in assoc(q, :activity),
+ select: %{id: type(q.id, :integer)},
+ where: is_nil(c.id)
+ )
+ |> Repo.chunk_stream(1_000, :batches)
+ |> Stream.each(fn records ->
+ notification_ids = Enum.map(records, fn %{id: id} -> id end)
+
+ Repo.delete_all(
+ from(n in "notifications",
+ where: n.id in ^notification_ids
+ )
+ )
+ end)
+ |> Stream.run()
+ end
+
+ def down do
+ :ok
+ end
+end
diff --git a/priv/repo/migrations/20200914105800_add_notification_constraints.exs b/priv/repo/migrations/20200914105800_add_notification_constraints.exs
new file mode 100644
index 000000000..a65c35fd0
--- /dev/null
+++ b/priv/repo/migrations/20200914105800_add_notification_constraints.exs
@@ -0,0 +1,23 @@
+defmodule Pleroma.Repo.Migrations.AddNotificationConstraints do
+ use Ecto.Migration
+
+ def up do
+ drop(constraint(:notifications, "notifications_activity_id_fkey"))
+
+ alter table(:notifications) do
+ modify(:activity_id, references(:activities, type: :uuid, on_delete: :delete_all),
+ null: false
+ )
+ end
+ end
+
+ def down do
+ drop(constraint(:notifications, "notifications_activity_id_fkey"))
+
+ alter table(:notifications) do
+ modify(:activity_id, references(:activities, type: :uuid, on_delete: :delete_all),
+ null: true
+ )
+ end
+ end
+end
diff --git a/priv/repo/migrations/20200915095704_remove_background_jobs.exs b/priv/repo/migrations/20200915095704_remove_background_jobs.exs
new file mode 100644
index 000000000..9785bfb8a
--- /dev/null
+++ b/priv/repo/migrations/20200915095704_remove_background_jobs.exs
@@ -0,0 +1,22 @@
+defmodule Pleroma.Repo.Migrations.RemoveBackgroundJobs do
+ use Ecto.Migration
+
+ import Ecto.Query, only: [from: 2]
+
+ def up do
+ from(j in "oban_jobs",
+ where:
+ j.queue == ^"background" and
+ fragment("?->>'op'", j.args) in ^[
+ "fetch_data_for_activity",
+ "media_proxy_prefetch",
+ "media_proxy_preload"
+ ] and
+ j.worker == ^"Pleroma.Workers.BackgroundWorker",
+ select: [:id]
+ )
+ |> Pleroma.Repo.delete_all()
+ end
+
+ def down, do: :ok
+end
diff --git a/priv/repo/migrations/20200919182636_remoteip_plug_rename.exs b/priv/repo/migrations/20200919182636_remoteip_plug_rename.exs
new file mode 100644
index 000000000..77c3b6db1
--- /dev/null
+++ b/priv/repo/migrations/20200919182636_remoteip_plug_rename.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.RemoteipPlugRename do
+ use Ecto.Migration
+
+ import Ecto.Query
+
+ def up do
+ config =
+ from(c in Pleroma.ConfigDB, where: c.group == ^:pleroma and c.key == ^Pleroma.Plugs.RemoteIp)
+ |> Pleroma.Repo.one()
+
+ if config do
+ config
+ |> Ecto.Changeset.change(key: Pleroma.Web.Plugs.RemoteIp)
+ |> Pleroma.Repo.update()
+ end
+ end
+
+ def down, do: :ok
+end
diff --git a/priv/repo/migrations/20200925065249_make_user_ids_ci.exs b/priv/repo/migrations/20200925065249_make_user_ids_ci.exs
new file mode 100644
index 000000000..8ea0f2cf1
--- /dev/null
+++ b/priv/repo/migrations/20200925065249_make_user_ids_ci.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.MakeUserIdsCI do
+ use Ecto.Migration
+
+ def change do
+ # Migration retired, see
+ # https://git.pleroma.social/pleroma/pleroma/-/issues/2188
+ :noop
+ end
+end
diff --git a/priv/repo/migrations/20200928145912_revert_citext_change.exs b/priv/repo/migrations/20200928145912_revert_citext_change.exs
new file mode 100644
index 000000000..685a98533
--- /dev/null
+++ b/priv/repo/migrations/20200928145912_revert_citext_change.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Repo.Migrations.RevertCitextChange do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ modify(:uri, :text)
+ end
+
+ # create_if_not_exists(unique_index(:users, :uri))
+ end
+end
diff --git a/priv/repo/migrations/20200930082320_user_ur_is_index_part_three.exs b/priv/repo/migrations/20200930082320_user_ur_is_index_part_three.exs
new file mode 100644
index 000000000..816c6526e
--- /dev/null
+++ b/priv/repo/migrations/20200930082320_user_ur_is_index_part_three.exs
@@ -0,0 +1,8 @@
+defmodule Pleroma.Repo.Migrations.UserURIsIndexPartThree do
+ use Ecto.Migration
+
+ def change do
+ drop_if_exists(unique_index(:users, :uri))
+ create_if_not_exists(index(:users, :uri))
+ end
+end
diff --git a/priv/repo/migrations/20201013141127_refactor_locked_user_field.exs b/priv/repo/migrations/20201013141127_refactor_locked_user_field.exs
new file mode 100644
index 000000000..6cd23dbac
--- /dev/null
+++ b/priv/repo/migrations/20201013141127_refactor_locked_user_field.exs
@@ -0,0 +1,15 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Repo.Migrations.RefactorLockedUserField do
+ use Ecto.Migration
+
+ def up do
+ execute("ALTER TABLE users RENAME COLUMN locked TO is_locked;")
+ end
+
+ def down do
+ execute("ALTER TABLE users RENAME COLUMN is_locked TO locked;")
+ end
+end
diff --git a/priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs b/priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs
new file mode 100644
index 000000000..3fdc190cc
--- /dev/null
+++ b/priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs
@@ -0,0 +1,15 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Repo.Migrations.RefactorDiscoverableUserField do
+ use Ecto.Migration
+
+ def up do
+ execute("ALTER TABLE users RENAME COLUMN discoverable TO is_discoverable;")
+ end
+
+ def down do
+ execute("ALTER TABLE users RENAME COLUMN is_discoverable TO discoverable;")
+ end
+end
diff --git a/priv/repo/migrations/20201113060459_remove_purge_expired_activity_worker_from_oban_config.exs b/priv/repo/migrations/20201113060459_remove_purge_expired_activity_worker_from_oban_config.exs
new file mode 100644
index 000000000..fe31f4442
--- /dev/null
+++ b/priv/repo/migrations/20201113060459_remove_purge_expired_activity_worker_from_oban_config.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.RemovePurgeExpiredActivityWorkerFromObanConfig do
+ use Ecto.Migration
+
+ def change do
+ with %Pleroma.ConfigDB{} = config <-
+ Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Oban}),
+ crontab when is_list(crontab) <- config.value[:crontab],
+ index when is_integer(index) <-
+ Enum.find_index(crontab, fn {_, worker} ->
+ worker == Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker
+ end) do
+ updated_value = Keyword.put(config.value, :crontab, List.delete_at(crontab, index))
+
+ config
+ |> Ecto.Changeset.change(value: updated_value)
+ |> Pleroma.Repo.update()
+ end
+ end
+end