From fefbd31c6e60e25778ed01c522273375d4f04266 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sun, 6 Oct 2019 16:22:35 +0300 Subject: Move local keys out of `user.info` --- priv/repo/migrations/20191006123824_add_keys_column.exs | 9 +++++++++ .../migrations/20191006135457_move_keys_to_separate_column.exs | 7 +++++++ 2 files changed, 16 insertions(+) create mode 100644 priv/repo/migrations/20191006123824_add_keys_column.exs create mode 100644 priv/repo/migrations/20191006135457_move_keys_to_separate_column.exs (limited to 'priv') diff --git a/priv/repo/migrations/20191006123824_add_keys_column.exs b/priv/repo/migrations/20191006123824_add_keys_column.exs new file mode 100644 index 000000000..b6c615646 --- /dev/null +++ b/priv/repo/migrations/20191006123824_add_keys_column.exs @@ -0,0 +1,9 @@ +defmodule Pleroma.Repo.Migrations.AddKeysColumn do + use Ecto.Migration + + def change do + alter table("users") do + add_if_not_exists :keys, :text + end + end +end diff --git a/priv/repo/migrations/20191006135457_move_keys_to_separate_column.exs b/priv/repo/migrations/20191006135457_move_keys_to_separate_column.exs new file mode 100644 index 000000000..504dde53a --- /dev/null +++ b/priv/repo/migrations/20191006135457_move_keys_to_separate_column.exs @@ -0,0 +1,7 @@ +defmodule Pleroma.Repo.Migrations.MoveKeysToSeparateColumn do + use Ecto.Migration + + def change do + execute("update users set keys = info->>'keys' where local", "update users set info = jsonb_set(info, '{keys}'::text[], to_jsonb(keys)) where local") + end +end -- cgit v1.2.3 From 125f96e7064aa0d714c91bf4a0c78c25734c64ef Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sun, 6 Oct 2019 17:05:51 +0300 Subject: Fix the use of queries with a schema in a migration --- .../20190711042024_copy_muted_to_muted_notifications.exs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'priv') diff --git a/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs b/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs index 50669902e..815d66549 100644 --- a/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs +++ b/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs @@ -1,15 +1,10 @@ defmodule Pleroma.Repo.Migrations.CopyMutedToMutedNotifications do use Ecto.Migration + import Ecto.Query alias Pleroma.User def change do - query = - User.Query.build(%{ - local: true, - active: true, - order_by: :id - }) - + query = from(u in "users", where: fragment("not (?->'deactivated' @> 'true')", u.info), select: %{info: u.info}, where: u.local == true, order_by: u.id) Pleroma.Repo.stream(query) |> Enum.each(fn %{info: %{mutes: mutes} = info} = user -> -- cgit v1.2.3 From ee88afb2e2d26defe18541dd2a57f8c34e191cb8 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sun, 6 Oct 2019 17:53:03 +0300 Subject: Fix muted notification migration only working with a schema Should also improve performance. I tested it on my local DB, but if anyone has a backup of <=1.0 db they can test this on, please do --- .../20190711042024_copy_muted_to_muted_notifications.exs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'priv') diff --git a/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs b/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs index 815d66549..b717cab2e 100644 --- a/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs +++ b/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs @@ -1,19 +1,8 @@ defmodule Pleroma.Repo.Migrations.CopyMutedToMutedNotifications do use Ecto.Migration - import Ecto.Query alias Pleroma.User def change do - query = from(u in "users", where: fragment("not (?->'deactivated' @> 'true')", u.info), select: %{info: u.info}, where: u.local == true, order_by: u.id) - Pleroma.Repo.stream(query) - |> Enum.each(fn - %{info: %{mutes: mutes} = info} = user -> - info_cng = - Ecto.Changeset.cast(info, %{muted_notifications: mutes}, [:muted_notifications]) - - Ecto.Changeset.change(user) - |> Ecto.Changeset.put_embed(:info, info_cng) - |> Pleroma.Repo.update() - end) + execute("update users set info = jsonb_set(info, '{muted_notifications}', info->'mutes', true) where local = true") end end -- cgit v1.2.3