diff --git a/changelog.d/rebased-migration.change b/changelog.d/rebased-migration.change new file mode 100644 index 000000000..53ae0951a --- /dev/null +++ b/changelog.d/rebased-migration.change @@ -0,0 +1 @@ +Add optional migrations for rollback from Rebased diff --git a/docs/installation/migrating_from_rebased.md b/docs/installation/migrating_from_rebased.md new file mode 100644 index 000000000..94fc8ffe5 --- /dev/null +++ b/docs/installation/migrating_from_rebased.md @@ -0,0 +1,44 @@ +# Migrating from Rebased + +## Code migration + +As Rebased only officially supported running from source code, we assume you're running it from source as well. To migrate source from upstream, you need to set the origin repository URL to upstream and pull the changes. + +```bash +git remote set-url origin https://git.pleroma.social/pleroma/pleroma +git pull -r +``` + +Then, install the dependencies and compile as usual: + +```bash +MIX_ENV=prod mix deps.get +MIX_ENV=prod mix compile +``` + +As Rebased recommends using [`asdf` version manager](https://asdf-vm.com/), you might want to either keep using it or switch to system Elixir installation. If you choose the latter, follow Pleroma installation instructions for your distribution and replace the Pleroma systemd service with one provided by Pleroma upstream. + +```bash +sudo cp /opt/pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service +sudo systemctl daemon-reload +``` + +Because Rebased doesn't come with a bundled frontend, you most likely have one installed in thhe `instance/static` directory. You can remove it, as Pleroma comes with a bundled frontend. Be sure not to remove other files you might have there, like custom emojis. + +## Database migration + +> Note: While it is not necessary to rollback Rebased-specific migrations because they don't include breaking changes, it is recommended to do so to keep the database clean. You will lose data related to Rebased-specific features, like the configured webhooks or user-defined location. Consider taking a backup. + +To rollback Rebased-specific migrations: + +```bash +MIX_ENV=prod mix ecto.rollback --migrations-path priv/repo/optional_migrations/rebased_rollbacks --all +``` + +Then, just + +```bash +MIX_ENV=prod mix ecto.migrate +``` + +to apply Pleroma database migrations. diff --git a/priv/repo/optional_migrations/rebased_rollbacks/20210612185407_add_email_list_field_to_users.exs b/priv/repo/optional_migrations/rebased_rollbacks/20210612185407_add_email_list_field_to_users.exs new file mode 100644 index 000000000..7dd37a6db --- /dev/null +++ b/priv/repo/optional_migrations/rebased_rollbacks/20210612185407_add_email_list_field_to_users.exs @@ -0,0 +1,14 @@ +# Adapted from Rebased +# https://gitlab.com/soapbox-pub/rebased/-/blob/main/priv/repo/migrations/20210612185407_add_email_list_field_to_users.exs + +defmodule Pleroma.Repo.Migrations.AddEmailListFieldToUsers do + use Ecto.Migration + + def up, do: :noop + + def down do + alter table(:users) do + remove_if_exists(:accepts_email_list, :boolean) + end + end +end diff --git a/priv/repo/optional_migrations/rebased_rollbacks/20220225164000_add_activity_assigned_account_index.exs b/priv/repo/optional_migrations/rebased_rollbacks/20220225164000_add_activity_assigned_account_index.exs new file mode 100644 index 000000000..fd2193a12 --- /dev/null +++ b/priv/repo/optional_migrations/rebased_rollbacks/20220225164000_add_activity_assigned_account_index.exs @@ -0,0 +1,13 @@ +defmodule Pleroma.Repo.Migrations.AddActivityAssignedAccountIndex do + use Ecto.Migration + + def up, do: :noop + + def down do + drop_if_exists( + index(:activities, ["(data->>'assigned_account')"], + name: :activities_assigned_account_index + ) + ) + end +end diff --git a/priv/repo/optional_migrations/rebased_rollbacks/20220314220000_add_location_to_users.exs b/priv/repo/optional_migrations/rebased_rollbacks/20220314220000_add_location_to_users.exs new file mode 100644 index 000000000..d2d317d63 --- /dev/null +++ b/priv/repo/optional_migrations/rebased_rollbacks/20220314220000_add_location_to_users.exs @@ -0,0 +1,11 @@ +defmodule Pleroma.Repo.Migrations.AddLocationToUsers do + use Ecto.Migration + + def up, do: :noop + + def down do + alter table(:users) do + remove_if_exists(:location, :string) + end + end +end diff --git a/priv/repo/optional_migrations/rebased_rollbacks/20220624104914_create_webhooks.exs b/priv/repo/optional_migrations/rebased_rollbacks/20220624104914_create_webhooks.exs new file mode 100644 index 000000000..421dc0107 --- /dev/null +++ b/priv/repo/optional_migrations/rebased_rollbacks/20220624104914_create_webhooks.exs @@ -0,0 +1,10 @@ +defmodule Pleroma.Repo.Migrations.CreateWebhooks do + use Ecto.Migration + + def up, do: :noop + + def down do + drop_if_exists(unique_index(:webhooks, [:url])) + drop_if_exists(table(:webhooks)) + end +end diff --git a/priv/repo/optional_migrations/rebased_rollbacks/20220819171321_add_pleroma_participation_accepted_to_notifications_enum.exs b/priv/repo/optional_migrations/rebased_rollbacks/20220819171321_add_pleroma_participation_accepted_to_notifications_enum.exs new file mode 100644 index 000000000..68d242309 --- /dev/null +++ b/priv/repo/optional_migrations/rebased_rollbacks/20220819171321_add_pleroma_participation_accepted_to_notifications_enum.exs @@ -0,0 +1,45 @@ +defmodule Pleroma.Repo.Migrations.AddPleromaParticipationAcceptedToNotificationsEnum do + use Ecto.Migration + + def up, do: :noop + + def down do + alter table(:notifications) do + modify(:type, :string) + end + + """ + delete from notifications where type in ('pleroma:participation_accepted', 'pleroma:participation_request', 'pleroma:event_reminder', 'pleroma:event_update') + """ + |> execute() + + """ + drop type if exists notification_type + """ + |> execute() + + """ + create type notification_type as enum ( + 'follow', + 'follow_request', + 'mention', + 'move', + 'pleroma:emoji_reaction', + 'pleroma:chat_mention', + 'reblog', + 'favourite', + 'pleroma:report', + 'poll', + 'status', + 'update' + ) + """ + |> execute() + + """ + alter table notifications + alter column type type notification_type using (type::notification_type) + """ + |> execute() + end +end diff --git a/priv/repo/optional_migrations/rebased_rollbacks/20220927220033_add_last_move_at_to_users.exs b/priv/repo/optional_migrations/rebased_rollbacks/20220927220033_add_last_move_at_to_users.exs new file mode 100644 index 000000000..3414d5fb5 --- /dev/null +++ b/priv/repo/optional_migrations/rebased_rollbacks/20220927220033_add_last_move_at_to_users.exs @@ -0,0 +1,11 @@ +defmodule Pleroma.Repo.Migrations.AddLastMoveAtToUsers do + use Ecto.Migration + + def up, do: :noop + + def down do + alter table(:users) do + remove_if_exists(:last_move_at, :naive_datetime) + end + end +end diff --git a/priv/repo/optional_migrations/rebased_rollbacks/20221029171353_add_internal_to_webhooks.exs b/priv/repo/optional_migrations/rebased_rollbacks/20221029171353_add_internal_to_webhooks.exs new file mode 100644 index 000000000..fc85eebb9 --- /dev/null +++ b/priv/repo/optional_migrations/rebased_rollbacks/20221029171353_add_internal_to_webhooks.exs @@ -0,0 +1,11 @@ +defmodule Pleroma.Repo.Migrations.AddInternalToWebhooks do + use Ecto.Migration + + def up, do: :noop + + def down do + alter table(:webhooks) do + remove_if_exists(:internal, :boolean) + end + end +end diff --git a/priv/repo/optional_migrations/rebased_rollbacks/20221207235104_add_events_index.exs b/priv/repo/optional_migrations/rebased_rollbacks/20221207235104_add_events_index.exs new file mode 100644 index 000000000..4e2709277 --- /dev/null +++ b/priv/repo/optional_migrations/rebased_rollbacks/20221207235104_add_events_index.exs @@ -0,0 +1,17 @@ +# Adapted from Rebased +# https://gitlab.com/soapbox-pub/rebased/-/blob/main/priv/repo/migrations/20221207235104_add_events_index.exs + +defmodule Pleroma.Repo.Migrations.AddEventsIndex do + use Ecto.Migration + + def up, do: :noop + + def down do + drop_if_exists( + index(:objects, ["(data->>'type')"], + where: "data->>'type' = 'Event'", + name: :objects_events + ) + ) + end +end