X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Frelease_tasks.ex;h=02dd6c325db8fc13e1bfae53522c4694534220e6;hb=c72676d22f9c2e9ed83ba793fe9a85efd7e9a544;hp=66a8b627fe574ddfaadc942c505658710386f201;hpb=d7ec0898e5aa7acae463760fd85d1ebf8307b4f9;p=akkoma
diff --git a/lib/pleroma/release_tasks.ex b/lib/pleroma/release_tasks.ex
index 66a8b627f..02dd6c325 100644
--- a/lib/pleroma/release_tasks.ex
+++ b/lib/pleroma/release_tasks.ex
@@ -1,20 +1,23 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ReleaseTasks do
+ @repo Pleroma.Repo
+
def run(args) do
[task | args] = String.split(args)
case task do
"migrate" -> migrate(args)
+ "create" -> create()
+ "rollback" -> rollback(args)
task -> mix_task(task, args)
end
end
defp mix_task(task, args) do
- # Modules are not loaded before application starts
- Mix.Tasks.Pleroma.Common.start_pleroma()
+ Application.load(:pleroma)
{:ok, modules} = :application.get_key(:pleroma, :modules)
module =
@@ -32,7 +35,32 @@ defmodule Pleroma.ReleaseTasks do
end
end
- defp migrate(_args) do
- :noop
+ def migrate(args) do
+ Mix.Tasks.Pleroma.Ecto.Migrate.run(args)
+ end
+
+ def rollback(args) do
+ Mix.Tasks.Pleroma.Ecto.Rollback.run(args)
+ end
+
+ def create do
+ Application.load(:pleroma)
+
+ case @repo.__adapter__.storage_up(@repo.config) do
+ :ok ->
+ IO.puts("The database for #{inspect(@repo)} has been created")
+
+ {:error, :already_up} ->
+ IO.puts("The database for #{inspect(@repo)} has already been created")
+
+ {:error, term} when is_binary(term) ->
+ IO.puts(:stderr, "The database for #{inspect(@repo)} couldn't be created: #{term}")
+
+ {:error, term} ->
+ IO.puts(
+ :stderr,
+ "The database for #{inspect(@repo)} couldn't be created: #{inspect(term)}"
+ )
+ end
end
end