diff options
Diffstat (limited to 'priv/repo/migrations')
6 files changed, 104 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs b/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs index cdc00d20b..a703af83f 100644 --- a/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs +++ b/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs @@ -4,6 +4,8 @@ defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do    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 diff --git a/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs b/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs index 832bd02a7..9e49ddacb 100644 --- a/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs +++ b/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs @@ -4,6 +4,8 @@ defmodule Pleroma.Repo.Migrations.MoveTokensExpirationIntoOban do    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 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  | 
