Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85806845
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/mix/tasks/pleroma/ecto/migrate.ex b/lib/mix/tasks/pleroma/ecto/ecto.ex
similarity index 52%
copy from lib/mix/tasks/pleroma/ecto/migrate.ex
copy to lib/mix/tasks/pleroma/ecto/ecto.ex
index 2c0abda85..af09cb289 100644
--- a/lib/mix/tasks/pleroma/ecto/migrate.ex
+++ b/lib/mix/tasks/pleroma/ecto/ecto.ex
@@ -1,96 +1,40 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-onl
-
-defmodule Mix.Tasks.Pleroma.Ecto.Migrate do
- use Mix.Task
- require Logger
- @shortdoc "Wrapper on `ecto.migrate` task."
-
- @aliases [
- n: :step,
- v: :to
- ]
-
- @switches [
- all: :boolean,
- step: :integer,
- to: :integer,
- quiet: :boolean,
- log_sql: :boolean,
- strict_version_order: :boolean,
- migrations_path: :string
- ]
-
- @moduledoc """
- Changes `Logger` level to `:info` before start migration.
- Changes level back when migration ends.
-
- ## Start migration
-
- mix pleroma.ecto.migrate [OPTIONS]
-
- Options:
- - see https://hexdocs.pm/ecto/2.0.0/Mix.Tasks.Ecto.Migrate.html
- """
-
- @impl true
- def run(args \\ []) do
- {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
-
- opts =
- if opts[:to] || opts[:step] || opts[:all],
- do: opts,
- else: Keyword.put(opts, :all, true)
-
- opts =
- if opts[:quiet],
- do: Keyword.merge(opts, log: false, log_sql: false),
- else: opts
-
- path = ensure_migrations_path(Pleroma.Repo, opts)
-
- level = Logger.level()
- Logger.configure(level: :info)
-
- {:ok, _, _} = Ecto.Migrator.with_repo(Pleroma.Repo, &Ecto.Migrator.run(&1, path, :up, opts))
-
- Logger.configure(level: level)
- end
-
+defmodule Mix.Tasks.Pleroma.Ecto do
@doc """
Ensures the given repository's migrations path exists on the file system.
"""
@spec ensure_migrations_path(Ecto.Repo.t(), Keyword.t()) :: String.t()
def ensure_migrations_path(repo, opts) do
path = opts[:migrations_path] || Path.join(source_repo_priv(repo), "migrations")
if not File.dir?(path) do
raise_missing_migrations(Path.relative_to_cwd(path), repo)
end
path
end
@doc """
Returns the private repository path relative to the source.
"""
def source_repo_priv(repo) do
config = repo.config()
priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
Path.join(File.cwd!(), priv)
end
defp raise_missing_migrations(path, repo) do
raise("""
Could not find migrations directory #{inspect(path)}
for repo #{inspect(repo)}.
This may be because you are in a new project and the
migration directory has not been created yet. Creating an
empty directory at the path above will fix this error.
If you expected existing migrations to be found, please
make sure your repository has been properly configured
and the configured path exists.
""")
end
end
diff --git a/lib/mix/tasks/pleroma/ecto/migrate.ex b/lib/mix/tasks/pleroma/ecto/migrate.ex
index 2c0abda85..22eafe76f 100644
--- a/lib/mix/tasks/pleroma/ecto/migrate.ex
+++ b/lib/mix/tasks/pleroma/ecto/migrate.ex
@@ -1,96 +1,61 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-onl
defmodule Mix.Tasks.Pleroma.Ecto.Migrate do
use Mix.Task
require Logger
+
@shortdoc "Wrapper on `ecto.migrate` task."
@aliases [
n: :step,
v: :to
]
@switches [
all: :boolean,
step: :integer,
to: :integer,
quiet: :boolean,
log_sql: :boolean,
strict_version_order: :boolean,
migrations_path: :string
]
@moduledoc """
Changes `Logger` level to `:info` before start migration.
Changes level back when migration ends.
## Start migration
mix pleroma.ecto.migrate [OPTIONS]
Options:
- see https://hexdocs.pm/ecto/2.0.0/Mix.Tasks.Ecto.Migrate.html
"""
@impl true
def run(args \\ []) do
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
opts =
if opts[:to] || opts[:step] || opts[:all],
do: opts,
else: Keyword.put(opts, :all, true)
opts =
if opts[:quiet],
do: Keyword.merge(opts, log: false, log_sql: false),
else: opts
- path = ensure_migrations_path(Pleroma.Repo, opts)
+ path = Mix.Tasks.Pleroma.Ecto.ensure_migrations_path(Pleroma.Repo, opts)
level = Logger.level()
Logger.configure(level: :info)
{:ok, _, _} = Ecto.Migrator.with_repo(Pleroma.Repo, &Ecto.Migrator.run(&1, path, :up, opts))
Logger.configure(level: level)
end
-
- @doc """
- Ensures the given repository's migrations path exists on the file system.
- """
- @spec ensure_migrations_path(Ecto.Repo.t(), Keyword.t()) :: String.t()
- def ensure_migrations_path(repo, opts) do
- path = opts[:migrations_path] || Path.join(source_repo_priv(repo), "migrations")
-
- if not File.dir?(path) do
- raise_missing_migrations(Path.relative_to_cwd(path), repo)
- end
-
- path
- end
-
- @doc """
- Returns the private repository path relative to the source.
- """
- def source_repo_priv(repo) do
- config = repo.config()
- priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
- Path.join(File.cwd!(), priv)
- end
-
- defp raise_missing_migrations(path, repo) do
- raise("""
- Could not find migrations directory #{inspect(path)}
- for repo #{inspect(repo)}.
- This may be because you are in a new project and the
- migration directory has not been created yet. Creating an
- empty directory at the path above will fix this error.
- If you expected existing migrations to be found, please
- make sure your repository has been properly configured
- and the configured path exists.
- """)
- end
end
diff --git a/lib/mix/tasks/pleroma/ecto/rollback.ex b/lib/mix/tasks/pleroma/ecto/rollback.ex
index f64adc08a..0033ceba4 100644
--- a/lib/mix/tasks/pleroma/ecto/rollback.ex
+++ b/lib/mix/tasks/pleroma/ecto/rollback.ex
@@ -1,62 +1,65 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-onl
defmodule Mix.Tasks.Pleroma.Ecto.Rollback do
use Mix.Task
require Logger
@shortdoc "Wrapper on `ecto.rollback` task"
@aliases [
n: :step,
v: :to
]
@switches [
all: :boolean,
step: :integer,
to: :integer,
start: :boolean,
quiet: :boolean,
log_sql: :boolean,
migrations_path: :string
]
@moduledoc """
Changes `Logger` level to `:info` before start rollback.
Changes level back when rollback ends.
## Start rollback
mix pleroma.ecto.rollback
Options:
- see https://hexdocs.pm/ecto/2.0.0/Mix.Tasks.Ecto.Rollback.html
"""
@impl true
def run(args \\ []) do
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
opts =
if opts[:to] || opts[:step] || opts[:all],
do: opts,
else: Keyword.put(opts, :step, 1)
opts =
if opts[:quiet],
do: Keyword.merge(opts, log: false, log_sql: false),
else: opts
+ path = Mix.Tasks.Pleroma.Ecto.ensure_migrations_path(Pleroma.Repo, opts)
+
level = Logger.level()
Logger.configure(level: :info)
if Pleroma.Config.get(:env) == :test do
Logger.info("Rollback succesfully")
else
- {:ok, _, _} = Ecto.Migrator.with_repo(Pleroma.Repo, &Ecto.Migrator.run(&1, :down, opts))
+ {:ok, _, _} =
+ Ecto.Migrator.with_repo(Pleroma.Repo, &Ecto.Migrator.run(&1, path, :down, opts))
end
Logger.configure(level: level)
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Oct 13, 12:34 PM (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1786759
Default Alt Text
(7 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment