logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

data_migration.ex (1256B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.DataMigration do
  5. use Ecto.Schema
  6. alias Pleroma.DataMigration
  7. alias Pleroma.DataMigration.State
  8. alias Pleroma.Repo
  9. import Ecto.Changeset
  10. import Ecto.Query
  11. @type t :: %__MODULE__{}
  12. schema "data_migrations" do
  13. field(:name, :string)
  14. field(:state, State, default: :pending)
  15. field(:feature_lock, :boolean, default: false)
  16. field(:params, :map, default: %{})
  17. field(:data, :map, default: %{})
  18. timestamps()
  19. end
  20. def changeset(data_migration, params \\ %{}) do
  21. data_migration
  22. |> cast(params, [:name, :state, :feature_lock, :params, :data])
  23. |> validate_required([:name])
  24. |> unique_constraint(:name)
  25. end
  26. def update_one_by_id(id, params \\ %{}) do
  27. with {1, _} <-
  28. from(dm in DataMigration, where: dm.id == ^id)
  29. |> Repo.update_all(set: params) do
  30. :ok
  31. end
  32. end
  33. def get_by_name(name) do
  34. Repo.get_by(DataMigration, name: name)
  35. end
  36. def populate_hashtags_table, do: get_by_name("populate_hashtags_table")
  37. def delete_context_objects, do: get_by_name("delete_context_objects")
  38. end