Application: Save postgres version in the environment
authorlain <lain@soykaf.club>
Fri, 20 Nov 2020 15:26:22 +0000 (16:26 +0100)
committerlain <lain@soykaf.club>
Fri, 20 Nov 2020 15:26:22 +0000 (16:26 +0100)
lib/pleroma/application.ex

index 8f08a6222173df3012d088534f7e668f688e75fd..f2a8c7825c544bd1fa11da1bb763bacfd0afd7f8 100644 (file)
@@ -109,7 +109,28 @@ defmodule Pleroma.Application do
     # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
     # for other strategies and supported options
     opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
-    Supervisor.start_link(children, opts)
+    result = Supervisor.start_link(children, opts)
+
+    set_postgres_server_version()
+
+    result
+  end
+
+  defp set_postgres_server_version() do
+    version =
+      with %{rows: [[version]]} <- Ecto.Adapters.SQL.query!(Pleroma.Repo, "show server_version"),
+           {num, _} <- Float.parse(version) do
+        num
+      else
+        e ->
+          Logger.warn(
+            "Could not get the postgres version: #{inspect(e)}.\nSetting the default value of 9.6"
+          )
+
+          9.6
+      end
+
+    Application.put_env(:postgres, :version, version)
   end
 
   def load_custom_modules do