logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

20210113225652_deprecate_public_endpoint.exs (1815B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Repo.Migrations.DeprecatePublicEndpoint do
  5. use Ecto.Migration
  6. def up do
  7. with %Pleroma.ConfigDB{} = s3_config <-
  8. Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}),
  9. %Pleroma.ConfigDB{} = upload_config <-
  10. Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}) do
  11. public_endpoint = s3_config.value[:public_endpoint]
  12. if !is_nil(public_endpoint) do
  13. upload_value = upload_config.value |> Keyword.merge(base_url: public_endpoint)
  14. upload_config
  15. |> Ecto.Changeset.change(value: upload_value)
  16. |> Pleroma.Repo.update()
  17. s3_value = s3_config.value |> Keyword.delete(:public_endpoint)
  18. s3_config
  19. |> Ecto.Changeset.change(value: s3_value)
  20. |> Pleroma.Repo.update()
  21. end
  22. else
  23. _ -> :ok
  24. end
  25. end
  26. def down do
  27. with %Pleroma.ConfigDB{} = upload_config <-
  28. Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}),
  29. %Pleroma.ConfigDB{} = s3_config <-
  30. Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}) do
  31. base_url = upload_config.value[:base_url]
  32. if !is_nil(base_url) do
  33. s3_value = s3_config.value |> Keyword.merge(public_endpoint: base_url)
  34. s3_config
  35. |> Ecto.Changeset.change(value: s3_value)
  36. |> Pleroma.Repo.update()
  37. upload_value = upload_config.value |> Keyword.delete(:base_url)
  38. upload_config
  39. |> Ecto.Changeset.change(value: upload_value)
  40. |> Pleroma.Repo.update()
  41. end
  42. else
  43. _ -> :ok
  44. end
  45. end
  46. end