Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85950840
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/pleroma/release_tasks.ex b/lib/pleroma/release_tasks.ex
index 66a8b627f..7726bc635 100644
--- a/lib/pleroma/release_tasks.ex
+++ b/lib/pleroma/release_tasks.ex
@@ -1,38 +1,64 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ReleaseTasks do
+ @repo Pleroma.Repo
+
def run(args) do
+ Mix.Tasks.Pleroma.Common.start_pleroma()
[task | args] = String.split(args)
case task do
- "migrate" -> migrate(args)
+ "migrate" -> migrate()
+ "create" -> create()
+ "rollback" -> rollback(String.to_integer(Enum.at(args, 0)))
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()
{:ok, modules} = :application.get_key(:pleroma, :modules)
module =
Enum.find(modules, fn module ->
module = Module.split(module)
match?(["Mix", "Tasks", "Pleroma" | _], module) and
String.downcase(List.last(module)) == task
end)
if module do
module.run(args)
else
IO.puts("The task #{task} does not exist")
end
end
- defp migrate(_args) do
- :noop
+ def migrate do
+ {:ok, _, _} = Ecto.Migrator.with_repo(@repo, &Ecto.Migrator.run(&1, :up, all: true))
+ end
+
+ def rollback(version) do
+ {:ok, _, _} = Ecto.Migrator.with_repo(@repo, &Ecto.Migrator.run(&1, :down, to: version))
+ end
+
+ def create do
+ 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
diff --git a/rel/pleroma_ctl b/rel/pleroma_ctl
index 16526af44..6137f19d3 100755
--- a/rel/pleroma_ctl
+++ b/rel/pleroma_ctl
@@ -1,5 +1,19 @@
#!/bin/sh
# XXX: This should be removed when elixir's releases get custom command support
-SCRIPT=$(readlink -f "$0")
-SCRIPTPATH=$(dirname "$SCRIPT")
-$SCRIPTPATH/pleroma eval 'Pleroma.ReleaseTasks.run("'"$*"'")'
+if [ -z "$1" ] || [ "$1" == "help" ]; then
+ echo "Usage: $(basename "$0") COMMAND [ARGS]
+
+ The known commands are:
+
+ create Create database schema (needs to be executed only once)
+ migrate Execute database migrations (needs to be done after updates)
+ rollback Rollback database migrations (needs to be done before downgrading)
+
+ and any mix tasks under Pleroma namespace, for example \`mix pleroma.user COMMAND\` is
+ equialent to \`$(basename "$0") user COMMAND\`
+"
+else
+ SCRIPT=$(readlink -f "$0")
+ SCRIPTPATH=$(dirname "$SCRIPT")
+ $SCRIPTPATH/pleroma eval 'Pleroma.ReleaseTasks.run("'"$*"'")'
+fi
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Nov 19, 1:12 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1840827
Default Alt Text
(3 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline