diff options
Diffstat (limited to 'priv/repo/migrations')
20 files changed, 357 insertions, 0 deletions
| 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/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/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/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 | 
