Merge pull request 'Add dark and light theme mode to docs, detection, and button...
[akkoma] / priv / repo / migrations / 20210113225652_deprecate_public_endpoint.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Repo.Migrations.DeprecatePublicEndpoint do
6 use Ecto.Migration
7
8 def up 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]
14
15 if !is_nil(public_endpoint) do
16 upload_value = upload_config.value |> Keyword.merge(base_url: public_endpoint)
17
18 upload_config
19 |> Ecto.Changeset.change(value: upload_value)
20 |> Pleroma.Repo.update()
21
22 s3_value = s3_config.value |> Keyword.delete(:public_endpoint)
23
24 s3_config
25 |> Ecto.Changeset.change(value: s3_value)
26 |> Pleroma.Repo.update()
27 end
28 else
29 _ -> :ok
30 end
31 end
32
33 def down do
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]
39
40 if !is_nil(base_url) do
41 s3_value = s3_config.value |> Keyword.merge(public_endpoint: base_url)
42
43 s3_config
44 |> Ecto.Changeset.change(value: s3_value)
45 |> Pleroma.Repo.update()
46
47 upload_value = upload_config.value |> Keyword.delete(:base_url)
48
49 upload_config
50 |> Ecto.Changeset.change(value: upload_value)
51 |> Pleroma.Repo.update()
52 end
53 else
54 _ -> :ok
55 end
56 end
57 end