diff options
author | Egor Kislitsyn <egor@kislitsyn.com> | 2019-10-24 14:42:14 +0700 |
---|---|---|
committer | Egor Kislitsyn <egor@kislitsyn.com> | 2019-10-24 14:55:36 +0700 |
commit | 4c1dd55c48f80f3ebdb26d1a0c1a75b7922f578c (patch) | |
tree | f296a9b23362e59daf1eac6b669886be8dab1576 /priv/repo/migrations | |
parent | 478f0883eb994c639923b7b27259a02bcef8708c (diff) | |
parent | 17c237ba808d4356bb1e202e459680563b79ef99 (diff) | |
download | pleroma-4c1dd55c48f80f3ebdb26d1a0c1a75b7922f578c.tar.gz |
Merge remote-tracking branch 'upstream/develop' into refactor/following-relationships
Diffstat (limited to 'priv/repo/migrations')
5 files changed, 210 insertions, 3 deletions
diff --git a/priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs b/priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs index 779aa382e..a5170d521 100644 --- a/priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs +++ b/priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs @@ -5,7 +5,11 @@ defmodule Pleroma.Repo.Migrations.AddFollowingAddressFromSourceData do def change do query = - User.external_users_query() + User.Query.build(%{ + external: true, + legacy_active: true, + order_by: :id + }) |> select([u], struct(u, [:id, :ap_id, :info])) Pleroma.Repo.stream(query) 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 a5eec848b..fc9bf70ba 100644 --- a/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs +++ b/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs @@ -1,6 +1,5 @@ defmodule Pleroma.Repo.Migrations.CopyMutedToMutedNotifications do use Ecto.Migration - alias Pleroma.User def change do execute( 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 new file mode 100644 index 000000000..9dd27511c --- /dev/null +++ b/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs @@ -0,0 +1,187 @@ +defmodule Pleroma.Repo.Migrations.CopyUsersInfoFieldsToUsers do + use Ecto.Migration + + @jsonb_array_default "'[]'::jsonb" + + @info_fields [ + :banner, + :background, + :source_data, + :note_count, + :follower_count, + :following_count, + :locked, + :confirmation_pending, + :password_reset_pending, + :confirmation_token, + :default_scope, + :blocks, + :domain_blocks, + :mutes, + :muted_reblogs, + :muted_notifications, + :subscribers, + :deactivated, + :no_rich_text, + :ap_enabled, + :is_moderator, + :is_admin, + :show_role, + :settings, + :magic_key, + :uri, + :hide_followers_count, + :hide_follows_count, + :hide_followers, + :hide_follows, + :hide_favorites, + :unread_conversation_count, + :pinned_activities, + :email_notifications, + :mascot, + :emoji, + :pleroma_settings_store, + :fields, + :raw_fields, + :discoverable, + :invisible, + :skip_thread_containment, + :notification_settings + ] + + @jsonb_fields [ + :banner, + :background, + :source_data, + :settings, + :email_notifications, + :mascot, + :pleroma_settings_store, + :notification_settings + ] + + @array_jsonb_fields [:emoji, :fields, :raw_fields] + + @int_fields [:note_count, :follower_count, :following_count, :unread_conversation_count] + + @boolean_fields [ + :locked, + :confirmation_pending, + :password_reset_pending, + :deactivated, + :no_rich_text, + :ap_enabled, + :is_moderator, + :is_admin, + :show_role, + :hide_followers_count, + :hide_follows_count, + :hide_followers, + :hide_follows, + :hide_favorites, + :discoverable, + :invisible, + :skip_thread_containment + ] + + @array_text_fields [ + :blocks, + :domain_blocks, + :mutes, + :muted_reblogs, + :muted_notifications, + :subscribers, + :pinned_activities + ] + + def change do + alter table(:users) do + add(:banner, :map, default: %{}) + add(:background, :map, default: %{}) + add(:source_data, :map, default: %{}) + add(:note_count, :integer, default: 0) + add(:follower_count, :integer, default: 0) + add(:following_count, :integer, default: nil) + add(:locked, :boolean, default: false, null: false) + add(:confirmation_pending, :boolean, default: false, null: false) + add(:password_reset_pending, :boolean, default: false, null: false) + add(:confirmation_token, :text, default: nil) + add(:default_scope, :string, default: "public") + add(:blocks, {:array, :text}, default: []) + add(:domain_blocks, {:array, :text}, default: []) + add(:mutes, {:array, :text}, default: []) + add(:muted_reblogs, {:array, :text}, default: []) + add(:muted_notifications, {:array, :text}, default: []) + add(:subscribers, {:array, :text}, default: []) + add(:deactivated, :boolean, default: false, null: false) + add(:no_rich_text, :boolean, default: false, null: false) + add(:ap_enabled, :boolean, default: false, null: false) + add(:is_moderator, :boolean, default: false, null: false) + add(:is_admin, :boolean, default: false, null: false) + add(:show_role, :boolean, default: true, null: false) + add(:settings, :map, default: nil) + add(:magic_key, :text, default: nil) + add(:uri, :text, default: nil) + add(:hide_followers_count, :boolean, default: false, null: false) + add(:hide_follows_count, :boolean, default: false, null: false) + add(:hide_followers, :boolean, default: false, null: false) + add(:hide_follows, :boolean, default: false, null: false) + add(:hide_favorites, :boolean, default: true, null: false) + add(:unread_conversation_count, :integer, default: 0) + add(:pinned_activities, {:array, :text}, default: []) + add(:email_notifications, :map, default: %{"digest" => false}) + add(:mascot, :map, default: nil) + add(:emoji, :map, default: fragment(@jsonb_array_default)) + add(:pleroma_settings_store, :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 + + if direction() == :up 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} #{jsonb}") + + f in @array_jsonb_fields -> + execute("#{set_field} coalesce(#{jsonb}, #{@jsonb_array_default})") + + f in @int_fields -> + execute("#{set_field} (info->>'#{f}')::int") + + f in @boolean_fields -> + execute("#{set_field} coalesce((info->>'#{f}')::boolean, false)") + + f in @array_text_fields -> + execute("#{set_field} ARRAY(SELECT jsonb_array_elements_text(#{jsonb}))") + + true -> + execute("#{set_field} info->>'#{f}'") + end + end + + for index_name <- [ + :users_deactivated_index, + :users_is_moderator_index, + :users_is_admin_index, + :users_subscribers_index + ] do + drop_if_exists(index(:users, [], name: index_name)) + end + end + + create_if_not_exists(index(:users, [:deactivated])) + create_if_not_exists(index(:users, [:is_moderator])) + create_if_not_exists(index(:users, [:is_admin])) + create_if_not_exists(index(:users, [:subscribers])) + end +end diff --git a/priv/repo/migrations/20191014181019_create_markers.exs b/priv/repo/migrations/20191014181019_create_markers.exs new file mode 100644 index 000000000..c717831ba --- /dev/null +++ b/priv/repo/migrations/20191014181019_create_markers.exs @@ -0,0 +1,15 @@ +defmodule Pleroma.Repo.Migrations.CreateMarkers do + use Ecto.Migration + + def change do + create_if_not_exists table(:markers) do + add(:user_id, references(:users, type: :uuid, on_delete: :delete_all)) + add(:timeline, :string, default: "", null: false) + add(:last_read_id, :string, default: "", null: false) + add(:lock_version, :integer, default: 0, null: false) + timestamps() + end + + create_if_not_exists(unique_index(:markers, [:user_id, :timeline])) + end +end diff --git a/priv/repo/migrations/20191017225002_drop_websub_tables.exs b/priv/repo/migrations/20191017225002_drop_websub_tables.exs index 9e483b2a1..4cf67a59c 100644 --- a/priv/repo/migrations/20191017225002_drop_websub_tables.exs +++ b/priv/repo/migrations/20191017225002_drop_websub_tables.exs @@ -1,8 +1,10 @@ defmodule Pleroma.Repo.Migrations.DropWebsubTables do use Ecto.Migration - def change do + def up do drop_if_exists(table(:websub_client_subscriptions)) drop_if_exists(table(:websub_server_subscriptions)) end + + def down, do: :noop end |