1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Repo.Migrations.DeprecatePublicEndpoint do
9 with %Pleroma.ConfigDB{} = s3_config <-
10 Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}),
11 %Pleroma.ConfigDB{} = upload_config <-
12 Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}) do
13 public_endpoint = s3_config.value[:public_endpoint]
15 if !is_nil(public_endpoint) do
16 upload_value = upload_config.value |> Keyword.merge(base_url: public_endpoint)
19 |> Ecto.Changeset.change(value: upload_value)
20 |> Pleroma.Repo.update()
22 s3_value = s3_config.value |> Keyword.delete(:public_endpoint)
25 |> Ecto.Changeset.change(value: s3_value)
26 |> Pleroma.Repo.update()
34 with %Pleroma.ConfigDB{} = upload_config <-
35 Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}),
36 %Pleroma.ConfigDB{} = s3_config <-
37 Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}) do
38 base_url = upload_config.value[:base_url]
40 if !is_nil(base_url) do
41 s3_value = s3_config.value |> Keyword.merge(public_endpoint: base_url)
44 |> Ecto.Changeset.change(value: s3_value)
45 |> Pleroma.Repo.update()
47 upload_value = upload_config.value |> Keyword.delete(:base_url)
50 |> Ecto.Changeset.change(value: upload_value)
51 |> Pleroma.Repo.update()