}
]
},
+ %{
+ group: :pleroma,
+ key: :database,
+ type: :group,
+ description: "Database-related settings",
+ children: [
+ %{
+ key: :improved_hashtag_timeline,
+ type: :keyword,
+ description:
+ "If `true`, hashtags will be fetched from `hashtags` table for hashtags timeline. When `false`, object-embedded hashtags will be used (slower). Is auto-set to `true` (unless overridden) when HashtagsTableMigrator completes."
+ }
+ ]
+ },
%{
group: :pleroma,
key: :instance,
key: :show_reactions,
type: :boolean,
description: "Let favourites and emoji reactions be viewed through the API."
- },
- %{
- key: :improved_hashtag_timeline,
- type: :keyword,
- description:
- "If `true`, hashtags will be fetched from `hashtags` table for hashtags timeline. When `false`, object-embedded hashtags will be used (slower). Is auto-set to `true` (unless overridden) when HashtagsTableMigrator completes."
}
]
},
@shortdoc "A collection of database related tasks"
@moduledoc File.read!("docs/administration/CLI_tasks/database.md")
- # Rolls back a specific migration (leaving subsequent migrations applied)
- # Based on https://stackoverflow.com/a/53825840
- def run(["rollback", version]) do
- start_pleroma()
-
- version = String.to_integer(version)
- re = ~r/^#{version}_.*\.exs/
- path = Application.app_dir(:pleroma, Path.join(["priv", "repo", "migrations"]))
-
- result =
- with {:find, "" <> file} <- {:find, Enum.find(File.ls!(path), &String.match?(&1, re))},
- {:compile, [{mod, _} | _]} <- {:compile, Code.compile_file(Path.join(path, file))},
- {:rollback, :ok} <- {:rollback, Ecto.Migrator.down(Repo, version, mod)} do
- {:ok, "Reversed migration: #{file}"}
- else
- {:find, _} -> {:error, "No migration found with version prefix: #{version}"}
- {:compile, e} -> {:error, "Problem compiling migration module: #{inspect(e)}"}
- {:rollback, e} -> {:error, "Problem reversing migration: #{inspect(e)}"}
- e -> {:error, "Something unexpected happened: #{inspect(e)}"}
- end
-
- IO.inspect(result)
- end
-
def run(["remove_embedded_objects" | args]) do
{options, [], []} =
OptionParser.parse(
end)
|> Stream.run()
end
+
+ # Rolls back a specific migration (leaving subsequent migrations applied).
+ # WARNING: imposes a risk of unrecoverable data loss — proceed at your own responsibility.
+ # Based on https://stackoverflow.com/a/53825840
+ def run(["rollback", version]) do
+ prompt = "SEVERE WARNING: this operation may result in unrecoverable data loss. Continue?"
+
+ if shell_prompt(prompt, "n") in ~w(Yn Y y) do
+ {_, result, _} =
+ Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
+ version = String.to_integer(version)
+ re = ~r/^#{version}_.*\.exs/
+ path = Ecto.Migrator.migrations_path(repo)
+
+ with {:find, "" <> file} <- {:find, Enum.find(File.ls!(path), &String.match?(&1, re))},
+ {:compile, [{mod, _} | _]} <- {:compile, Code.compile_file(Path.join(path, file))},
+ {:rollback, :ok} <- {:rollback, Ecto.Migrator.down(repo, version, mod)} do
+ {:ok, "Reversed migration: #{file}"}
+ else
+ {:find, _} -> {:error, "No migration found with version prefix: #{version}"}
+ {:compile, e} -> {:error, "Problem compiling migration module: #{inspect(e)}"}
+ {:rollback, e} -> {:error, "Problem reversing migration: #{inspect(e)}"}
+ e -> {:error, "Something unexpected happened: #{inspect(e)}"}
+ end
+ end)
+
+ IO.inspect(result)
+ end
+ end
end
alias Pleroma.Hashtag
alias Pleroma.Repo
- @derive {Jason.Encoder, only: [:data]}
-
schema "hashtags" do
field(:name, :string)
- field(:data, :map, default: %{})
many_to_many(:objects, Pleroma.Object, join_through: "hashtags_objects", on_replace: :delete)
def changeset(%Hashtag{} = struct, params) do
struct
- |> cast(params, [:name, :data])
+ |> cast(params, [:name])
|> update_change(:name, &String.downcase/1)
|> validate_required([:name])
|> unique_constraint(:name)