X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=priv%2Frepo%2Fmigrations%2F20191009154608_copy_users_info_fields_to_users.exs;h=9dd27511cce153ae4067a2032589f24a959c0c8d;hb=cd0218c2053b3f7e04416ea0eb12759d78cfcbf5;hp=72c852d2b0a15925653b196f2e25e905c06c50dd;hpb=a11a7176d59deafa08a865d6e0950b9b9c540f18;p=akkoma diff --git a/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs b/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs index 72c852d2b..9dd27511c 100644 --- a/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs +++ b/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs @@ -1,6 +1,8 @@ defmodule Pleroma.Repo.Migrations.CopyUsersInfoFieldsToUsers do use Ecto.Migration + @jsonb_array_default "'[]'::jsonb" + @info_fields [ :banner, :background, @@ -42,6 +44,7 @@ defmodule Pleroma.Repo.Migrations.CopyUsersInfoFieldsToUsers do :fields, :raw_fields, :discoverable, + :invisible, :skip_thread_containment, :notification_settings ] @@ -77,6 +80,7 @@ defmodule Pleroma.Repo.Migrations.CopyUsersInfoFieldsToUsers do :hide_follows, :hide_favorites, :discoverable, + :invisible, :skip_thread_containment ] @@ -127,11 +131,12 @@ defmodule Pleroma.Repo.Migrations.CopyUsersInfoFieldsToUsers do add(:pinned_activities, {:array, :text}, default: []) add(:email_notifications, :map, default: %{"digest" => false}) add(:mascot, :map, default: nil) - add(:emoji, {:array, :map}, default: []) + add(:emoji, :map, default: fragment(@jsonb_array_default)) add(:pleroma_settings_store, :map, default: %{}) - add(:fields, {:array, :map}, default: nil) - add(:raw_fields, {:array, :map}, default: []) + add(:fields, :map, default: fragment(@jsonb_array_default)) + add(:raw_fields, :map, default: fragment(@jsonb_array_default)) add(:discoverable, :boolean, default: false, null: false) + add(:invisible, :boolean, default: false, null: false) add(:notification_settings, :map, default: %{}) add(:skip_thread_containment, :boolean, default: false, null: false) end @@ -140,12 +145,15 @@ defmodule Pleroma.Repo.Migrations.CopyUsersInfoFieldsToUsers do for f <- @info_fields do set_field = "update users set #{f} =" + # Coercion of null::jsonb to NULL + jsonb = "case when info->>'#{f}' IS NULL then null else info->'#{f}' end" + cond do f in @jsonb_fields -> - execute("#{set_field} info->'#{f}'") + execute("#{set_field} #{jsonb}") f in @array_jsonb_fields -> - execute("#{set_field} ARRAY(SELECT jsonb_array_elements(info->'#{f}'))") + execute("#{set_field} coalesce(#{jsonb}, #{@jsonb_array_default})") f in @int_fields -> execute("#{set_field} (info->>'#{f}')::int") @@ -154,7 +162,7 @@ defmodule Pleroma.Repo.Migrations.CopyUsersInfoFieldsToUsers do execute("#{set_field} coalesce((info->>'#{f}')::boolean, false)") f in @array_text_fields -> - execute("#{set_field} ARRAY(SELECT jsonb_array_elements_text(info->'#{f}'))") + execute("#{set_field} ARRAY(SELECT jsonb_array_elements_text(#{jsonb}))") true -> execute("#{set_field} info->>'#{f}'")