Migrations: delete contexts with BaseMigrator

Due to the lengthiness of this task, the migration has been adapted into
a BaseMigrator migration, running in the background instead.
This commit is contained in:
Hélène 2022-08-15 01:15:23 +02:00
commit 88c1c76d3e
No known key found for this signature in database
GPG key ID: A215F2E9F1589D62
6 changed files with 173 additions and 6 deletions

View file

@ -3,13 +3,16 @@ defmodule Pleroma.Repo.Migrations.DataMigrationDeleteContextObjects do
require Logger
@doc "This migration removes objects created exclusively for contexts, containing only an `id` field."
def up do
dt = NaiveDateTime.utc_now()
def change do
Logger.warn(
"This migration can take a very long time to execute, depending on your database size. Please be patient, Pleroma-tan is doing her best!\n"
execute(
"INSERT INTO data_migrations(name, inserted_at, updated_at) " <>
"VALUES ('delete_context_objects', '#{dt}', '#{dt}') ON CONFLICT DO NOTHING;"
)
end
execute("DELETE FROM objects WHERE (data->>'type') IS NULL;")
def down do
execute("DELETE FROM data_migrations WHERE name = 'delete_context_objects';")
end
end