2021-01-13 12:07:38 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2021-01-13 12:07:38 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.DataMigration do
|
|
|
|
use Ecto.Schema
|
|
|
|
|
|
|
|
alias Pleroma.DataMigration
|
|
|
|
alias Pleroma.DataMigration.State
|
|
|
|
alias Pleroma.Repo
|
|
|
|
|
|
|
|
import Ecto.Changeset
|
2021-02-16 13:14:15 -07:00
|
|
|
import Ecto.Query
|
2021-01-13 12:07:38 -07:00
|
|
|
|
|
|
|
schema "data_migrations" do
|
|
|
|
field(:name, :string)
|
|
|
|
field(:state, State, default: :pending)
|
|
|
|
field(:feature_lock, :boolean, default: false)
|
|
|
|
field(:params, :map, default: %{})
|
|
|
|
field(:data, :map, default: %{})
|
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
def changeset(data_migration, params \\ %{}) do
|
|
|
|
data_migration
|
|
|
|
|> cast(params, [:name, :state, :feature_lock, :params, :data])
|
|
|
|
|> validate_required([:name])
|
|
|
|
|> unique_constraint(:name)
|
|
|
|
end
|
|
|
|
|
2021-02-16 13:14:15 -07:00
|
|
|
def update_one_by_id(id, params \\ %{}) do
|
|
|
|
with {1, _} <-
|
|
|
|
from(dm in DataMigration, where: dm.id == ^id)
|
|
|
|
|> Repo.update_all(set: params) do
|
|
|
|
:ok
|
|
|
|
end
|
2021-01-13 12:07:38 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_by_name(name) do
|
|
|
|
Repo.get_by(DataMigration, name: name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def populate_hashtags_table, do: get_by_name("populate_hashtags_table")
|
2022-08-14 17:15:23 -06:00
|
|
|
def delete_context_objects, do: get_by_name("delete_context_objects")
|
2021-01-13 12:07:38 -07:00
|
|
|
end
|