Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 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. schema "data_migrations" do
  12. field(:name, :string)
  13. field(:state, State, default: :pending)
  14. field(:feature_lock, :boolean, default: false)
  15. field(:params, :map, default: %{})
  16. field(:data, :map, default: %{})
  17. timestamps()
  18. end
  19. def changeset(data_migration, params \\ %{}) do
  20. data_migration
  21. |> cast(params, [:name, :state, :feature_lock, :params, :data])
  22. |> validate_required([:name])
  23. |> unique_constraint(:name)
  24. end
  25. def update_one_by_id(id, params \\ %{}) do
  26. with {1, _} <-
  27. from(dm in DataMigration, where: dm.id == ^id)
  28. |> Repo.update_all(set: params) do
  29. :ok
  30. end
  31. end
  32. def get_by_name(name) do
  33. Repo.get_by(DataMigration, name: name)
  34. end
  35. def populate_hashtags_table, do: get_by_name("populate_hashtags_table")
  36. end