1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ApplicationRequirements do
7 The module represents the collection of validations to runs before start server.
10 defmodule VerifyError, do: defexception([:message])
16 @spec verify!() :: :ok | VerifyError.t()
19 |> check_confirmation_accounts!
20 |> check_migrations_applied!()
25 defp handle_result(:ok), do: :ok
26 defp handle_result({:error, message}), do: raise(VerifyError, message: message)
28 # Checks account confirmation email
30 def check_confirmation_accounts!(:ok) do
31 if Pleroma.Config.get([:instance, :account_activation_required]) &&
32 not Pleroma.Config.get([Pleroma.Emails.Mailer, :enabled]) do
34 "Account activation enabled, but no Mailer settings enabled.\nPlease set config :pleroma, :instance, account_activation_required: false\nOtherwise setup and enable Mailer."
38 "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails."}
44 def check_confirmation_accounts!(result), do: result
46 # Checks for pending migrations.
48 def check_migrations_applied!(:ok) do
49 unless Pleroma.Config.get(
50 [:i_am_aware_this_may_cause_data_loss, :disable_migration_check],
54 Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
56 Ecto.Migrator.migrations(repo)
59 {:down, _, _} -> false
62 if length(down_migrations) > 0 do
63 down_migrations_text =
64 Enum.map(down_migrations, fn {:down, id, name} -> "- #{name} (#{id})\n" end)
67 "The following migrations were not applied:\n#{down_migrations_text}If you want to start Pleroma anyway, set\nconfig :pleroma, :i_am_aware_this_may_cause_data_loss, disable_migration_check: true"
70 {:error, "Unapplied Migrations detected"}
82 def check_migrations_applied!(result), do: result
84 # Checks for settings of RUM indexes.
86 defp check_rum!(:ok) do
88 Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
91 where: o.table_name == "objects",
92 where: o.column_name == "fts_content"
94 |> repo.exists?(prefix: "information_schema")
96 setting = Pleroma.Config.get([:database, :rum_enabled], false)
98 do_check_rum!(setting, migrate)
104 defp check_rum!(result), do: result
106 defp do_check_rum!(setting, migrate) do
107 case {setting, migrate} do
110 "Use `RUM` index is enabled, but were not applied migrations for it.\nIf you want to start Pleroma anyway, set\nconfig :pleroma, :database, rum_enabled: false\nOtherwise apply the following migrations:\n`mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/`"
113 {:error, "Unapplied RUM Migrations detected"}
117 "Detected applied migrations to use `RUM` index, but `RUM` isn't enable in settings.\nIf you want to use `RUM`, set\nconfig :pleroma, :database, rum_enabled: true\nOtherwise roll `RUM` migrations back.\n`mix ecto.rollback --migrations-path priv/repo/optional_migrations/rum_indexing/`"
120 {:error, "RUM Migrations detected"}