From 3a13f91fff3815a19ab61266111bb0ff5669af6e Mon Sep 17 00:00:00 2001 From: ilja Date: Fri, 9 Jun 2023 22:02:26 +0200 Subject: [PATCH] Adapt some migrations so they can be rolled back This is useful for people who want to migrate back to Pleroma. It's also added in the docs, but also noted that this is barely tested and to be used at their own risk. --- docs/docs/installation/migrating_to_akkoma.md | 14 +++++++++++++- ...0211125110126_force_pinned_objects_to_exist.exs | 10 +++++++++- .../20220108213213_add_mastofe_settings.exs | 8 +++++++- .../20220302013920_add_language_to_users.exs | 8 +++++++- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/docs/docs/installation/migrating_to_akkoma.md b/docs/docs/installation/migrating_to_akkoma.md index 2df7bfad0..4a58e836e 100644 --- a/docs/docs/installation/migrating_to_akkoma.md +++ b/docs/docs/installation/migrating_to_akkoma.md @@ -117,4 +117,16 @@ To fix this, run: mix pleroma.config delete pleroma frontends ``` -which will remove the config from the database. Things should work now. \ No newline at end of file +which will remove the config from the database. Things should work now. + +## Migrating back to Pleroma + +Akkoma is a hard fork of Pleroma. As such, migrating back is not guaranteed to always work. But if you want to migrate back to Pleroma, you can always try. Just note that you may run into unexpected issues and you're basically on your own. The following are some tips that may help, but note that these are barely tested, so proceed at your own risk. + +First you will need to roll back the database migrations. The latest migration both Akkoma and Pleroma still have in common should be 20210416051708, so roll back to that. If you run from source, that should be + +```sh +MIX_ENV=prod mix ecto.rollback --to 20210416051708 +``` + +Then switch back to Pleroma for updates (similar to how was done to migrate to Akkoma), and remove the front-ends. The front-ends are installed in the `frontends` folder in the [static directory](../configuration/static_dir.md). Once you are back to Pleroma, you will need to run the database migrations again. See the Pleroma documentation for this. diff --git a/priv/repo/migrations/20211125110126_force_pinned_objects_to_exist.exs b/priv/repo/migrations/20211125110126_force_pinned_objects_to_exist.exs index 1fe9271f0..c2b136d43 100644 --- a/priv/repo/migrations/20211125110126_force_pinned_objects_to_exist.exs +++ b/priv/repo/migrations/20211125110126_force_pinned_objects_to_exist.exs @@ -1,11 +1,19 @@ defmodule Pleroma.Repo.Migrations.ForcePinnedObjectsToExist do use Ecto.Migration - def change do + def up do execute("UPDATE users SET pinned_objects = '{}' WHERE pinned_objects IS NULL") alter table("users") do modify(:pinned_objects, :map, null: false, default: %{}) end end + + def down do + alter table("users") do + modify(:pinned_objects, :map, null: true, default: nil) + end + + execute("UPDATE users SET pinned_objects = NULL WHERE pinned_objects = '{}'") + end end diff --git a/priv/repo/migrations/20220108213213_add_mastofe_settings.exs b/priv/repo/migrations/20220108213213_add_mastofe_settings.exs index 1046c2894..dc7777d53 100644 --- a/priv/repo/migrations/20220108213213_add_mastofe_settings.exs +++ b/priv/repo/migrations/20220108213213_add_mastofe_settings.exs @@ -1,9 +1,15 @@ defmodule Pleroma.Repo.Migrations.AddMastofeSettings do use Ecto.Migration - def change do + def up do alter table(:users) do add_if_not_exists(:mastofe_settings, :map) end end + + def down do + alter table(:users) do + remove_if_exists(:mastofe_settings, :map) + end + end end diff --git a/priv/repo/migrations/20220302013920_add_language_to_users.exs b/priv/repo/migrations/20220302013920_add_language_to_users.exs index 7a63c36aa..fc5008993 100644 --- a/priv/repo/migrations/20220302013920_add_language_to_users.exs +++ b/priv/repo/migrations/20220302013920_add_language_to_users.exs @@ -1,9 +1,15 @@ defmodule Pleroma.Repo.Migrations.AddLanguageToUsers do use Ecto.Migration - def change do + def up do alter table(:users) do add_if_not_exists(:language, :string) end end + + def down do + alter table(:users) do + remove_if_exists(:language, :string) + end + end end