From 32808208bef12996f819d21ca2635837aff98cbf Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 8 Oct 2019 15:16:39 +0300 Subject: [PATCH 1/6] Enable `mix format` for migrations --- .formatter.exs | 2 +- .../migrations/20170320193800_create_user.exs | 11 ++- .../20170321074828_create_activity.exs | 5 +- .../20170321074832_create_object.exs | 3 +- ...0321133335_add_following_list_to_users.exs | 2 +- .../20170321143152_add_ap_id_to_users.exs | 2 +- .../20170330153447_add_index_to_objects.exs | 2 +- ...add_unique_index_to_email_and_nickname.exs | 4 +- ...70416122418_add_avatar_object_to_users.exs | 2 +- ...143_create_webssub_server_subscription.exs | 10 +-- .../20170423154511_add_fields_to_users.exs | 4 +- ...4155_create_websub_client_subscription.exs | 10 +-- .../20170427054757_add_user_and_hub.exs | 4 +- ...nts_to_activities_and_objects_part_two.exs | 14 ++- ...02083023_add_local_field_to_activities.exs | 4 +- ...0170506222027_add_unique_index_to_apid.exs | 2 +- .../migrations/20170529093232_longer_bios.exs | 5 +- ...20170620095947_remove_activities_index.exs | 2 +- ...420_add_object_activity_index_part_two.exs | 13 ++- ...0701142005_add_actor_index_to_activity.exs | 4 +- ...719152213_add_follower_address_to_user.exs | 4 +- .../20170906120646_add_mastodon_apps.exs | 12 +-- ...906143140_create_o_auth_authorizations.exs | 10 +-- .../20170906152508_create_o_auth_token.exs | 10 +-- .../20170911123607_create_notifications.exs | 8 +- .../20170912114248_add_context_index.exs | 7 +- ...0916090107_add_fts_index_to_activities.exs | 8 +- .../20170917120416_add_tag_index.exs | 8 +- ...019141706_create_password_reset_tokens.exs | 6 +- ...035_add_second_object_index_to_activty.exs | 14 ++- .../20171024090137_drop_object_index.exs | 2 +- .../20171024121413_add_object_actor_index.exs | 7 +- .../20171109091239_add_actor_to_activity.exs | 9 +- .../20171109114020_fill_actor_field.exs | 9 +- ...109141309_add_sort_index_to_activities.exs | 2 +- ...20171130135819_add_local_index_to_user.exs | 2 +- ...212163643_add_recipients_to_activities.exs | 4 +- ...12164525_fill_recipients_in_activities.exs | 12 ++- ...21210540_make_following_postgres_array.exs | 11 +-- ...51_add_follower_address_index_to_users.exs | 4 +- ...7174350_drop_local_index_on_activities.exs | 2 +- ...180327175831_actually_drop_local_index.exs | 4 +- .../20180429094642_create_lists.exs | 8 +- .../20180513104714_modify_activity_index.exs | 4 +- .../20180516144508_add_trigram_extension.exs | 11 ++- ...180516154905_create_user_trigram_index.exs | 4 +- .../20180530123448_add_list_follow_index.exs | 2 +- ...3637_create_apid_host_extraction_index.exs | 7 +- ...180612110515_create_user_invite_tokens.exs | 4 +- ...40_create_activities_in_reply_to_index.exs | 7 +- .../20180813003722_create_filters.exs | 21 +++-- ...ipients_to_and_cc_fields_to_activities.exs | 8 +- ...829182612_activities_add_to_cc_indices.exs | 9 +- ...ients_to_and_cc_fields_from_activities.exs | 8 +- ...903114437_users_add_is_moderator_index.exs | 4 +- ...180918182427_create_push_subscriptions.exs | 14 +-- ...0919060348_users_add_last_refreshed_at.exs | 2 +- .../20181206125616_add_tags_to_users.exs | 4 +- .../20181214121049_add_bookmarks_to_users.exs | 2 +- ...18172826_users_and_activities_flake_id.exs | 85 +++++++++++-------- ...20190109152453_add_visibility_function.exs | 4 +- .../20190115085500_create_user_fts_index.exs | 24 +++--- ...90122153157_update_activity_visibility.exs | 2 - ...0190123092341_users_add_is_admin_index.exs | 4 +- .../20190123125546_create_instances.exs | 8 +- ...31141_update_activity_visibility_again.exs | 3 - ...90127151220_add_activities_likes_index.exs | 8 +- .../20190203185340_split_hide_network.exs | 14 ++- .../20190205114625_create_thread_mutes.exs | 6 +- ...08131753_add_scopes_to_o_auth_entities.exs | 2 +- ...03_change_apps_scopes_to_varchar_array.exs | 18 ++-- ..._data_migration_populate_o_auth_scopes.exs | 2 +- ...104808_data_migration_normalize_scopes.exs | 2 +- ...0190301101154_add_default_tags_to_user.exs | 2 +- ...190303120636_update_user_note_counters.exs | 8 +- .../20190315101315_create_registrations.exs | 14 +-- ...325185009_create_notification_id_index.exs | 2 +- ...0190405160700_add_index_on_subscribers.exs | 8 +- .../20190408123347_create_conversations.exs | 6 +- ...859_add_participation_updated_at_index.exs | 2 +- ...120_add_index_on_user_info_deactivated.exs | 4 +- .../20190414125034_migrate_old_bookmarks.exs | 4 +- ...0190501125843_add_fts_index_to_objects.exs | 15 +++- ...511191044_set_default_state_to_reports.exs | 8 +- ...809_change_hide_column_in_filter_table.exs | 4 +- ...603162018_add_object_in_reply_to_index.exs | 2 +- ...0190603173419_add_tag_index_to_objects.exs | 7 +- ...2024_copy_muted_to_muted_notifications.exs | 4 +- ...ersation_participation_recipient_ships.exs | 4 +- ...90823000549_add_likes_index_to_objects.exs | 2 +- .../20190912065617_create_deliveries.exs | 3 +- ...0929201536_drop_subscription_if_exists.exs | 2 +- .../20191006123824_add_keys_column.exs | 2 +- ...006135457_move_keys_to_separate_column.exs | 5 +- 94 files changed, 405 insertions(+), 264 deletions(-) diff --git a/.formatter.exs b/.formatter.exs index 2bed17cc0..7fa95a619 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,3 +1,3 @@ [ - inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"] + inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}", "priv/repo/migrations/*.exs"] ] diff --git a/priv/repo/migrations/20170320193800_create_user.exs b/priv/repo/migrations/20170320193800_create_user.exs index 089964a26..e5f6ac52e 100644 --- a/priv/repo/migrations/20170320193800_create_user.exs +++ b/priv/repo/migrations/20170320193800_create_user.exs @@ -3,14 +3,13 @@ defmodule Pleroma.Repo.Migrations.CreatePleroma.User do def change do create_if_not_exists table(:users) do - add :email, :string - add :password_hash, :string - add :name, :string - add :nickname, :string - add :bio, :string + add(:email, :string) + add(:password_hash, :string) + add(:name, :string) + add(:nickname, :string) + add(:bio, :string) timestamps() end - end end diff --git a/priv/repo/migrations/20170321074828_create_activity.exs b/priv/repo/migrations/20170321074828_create_activity.exs index f5c872721..ab00a47c3 100644 --- a/priv/repo/migrations/20170321074828_create_activity.exs +++ b/priv/repo/migrations/20170321074828_create_activity.exs @@ -3,12 +3,11 @@ defmodule Pleroma.Repo.Migrations.CreatePleroma.Activity do def change do create_if_not_exists table(:activities) do - add :data, :map + add(:data, :map) timestamps() end - create_if_not_exists index(:activities, [:data], using: :gin) - + create_if_not_exists(index(:activities, [:data], using: :gin)) end end diff --git a/priv/repo/migrations/20170321074832_create_object.exs b/priv/repo/migrations/20170321074832_create_object.exs index b184672ad..c5a59ecba 100644 --- a/priv/repo/migrations/20170321074832_create_object.exs +++ b/priv/repo/migrations/20170321074832_create_object.exs @@ -3,10 +3,9 @@ defmodule Pleroma.Repo.Migrations.CreatePleroma.Object do def change do create_if_not_exists table(:objects) do - add :data, :map + add(:data, :map) timestamps() end - end end diff --git a/priv/repo/migrations/20170321133335_add_following_list_to_users.exs b/priv/repo/migrations/20170321133335_add_following_list_to_users.exs index b02c1272c..8dd83c3f8 100644 --- a/priv/repo/migrations/20170321133335_add_following_list_to_users.exs +++ b/priv/repo/migrations/20170321133335_add_following_list_to_users.exs @@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.AddFollowingListToUsers do def change do alter table(:users) do - add :following, :map + add(:following, :map) end end end diff --git a/priv/repo/migrations/20170321143152_add_ap_id_to_users.exs b/priv/repo/migrations/20170321143152_add_ap_id_to_users.exs index e6f0366b5..38ceb87fd 100644 --- a/priv/repo/migrations/20170321143152_add_ap_id_to_users.exs +++ b/priv/repo/migrations/20170321143152_add_ap_id_to_users.exs @@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.AddApIdToUsers do def change do alter table(:users) do - add :ap_id, :string + add(:ap_id, :string) end end end diff --git a/priv/repo/migrations/20170330153447_add_index_to_objects.exs b/priv/repo/migrations/20170330153447_add_index_to_objects.exs index 25e308533..93198b462 100644 --- a/priv/repo/migrations/20170330153447_add_index_to_objects.exs +++ b/priv/repo/migrations/20170330153447_add_index_to_objects.exs @@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.AddIndexToObjects do use Ecto.Migration def change do - create_if_not_exists index(:objects, [:data], using: :gin) + create_if_not_exists(index(:objects, [:data], using: :gin)) end end diff --git a/priv/repo/migrations/20170415141210_add_unique_index_to_email_and_nickname.exs b/priv/repo/migrations/20170415141210_add_unique_index_to_email_and_nickname.exs index 42da88954..b18c67dcb 100644 --- a/priv/repo/migrations/20170415141210_add_unique_index_to_email_and_nickname.exs +++ b/priv/repo/migrations/20170415141210_add_unique_index_to_email_and_nickname.exs @@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.AddUniqueIndexToEmailAndNickname do use Ecto.Migration def change do - create_if_not_exists unique_index(:users, [:email]) - create_if_not_exists unique_index(:users, [:nickname]) + create_if_not_exists(unique_index(:users, [:email])) + create_if_not_exists(unique_index(:users, [:nickname])) end end diff --git a/priv/repo/migrations/20170416122418_add_avatar_object_to_users.exs b/priv/repo/migrations/20170416122418_add_avatar_object_to_users.exs index b6d8742dc..e88752c30 100644 --- a/priv/repo/migrations/20170416122418_add_avatar_object_to_users.exs +++ b/priv/repo/migrations/20170416122418_add_avatar_object_to_users.exs @@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.AddAvatarObjectToUsers do def change do alter table(:users) do - add :avatar, :map + add(:avatar, :map) end end end diff --git a/priv/repo/migrations/20170418200143_create_webssub_server_subscription.exs b/priv/repo/migrations/20170418200143_create_webssub_server_subscription.exs index 243280378..3d94e4ee7 100644 --- a/priv/repo/migrations/20170418200143_create_webssub_server_subscription.exs +++ b/priv/repo/migrations/20170418200143_create_webssub_server_subscription.exs @@ -3,11 +3,11 @@ defmodule Pleroma.Repo.Migrations.CreateWebsubServerSubscription do def change do create_if_not_exists table(:websub_server_subscriptions) do - add :topic, :string - add :callback, :string - add :secret, :string - add :valid_until, :naive_datetime - add :state, :string + add(:topic, :string) + add(:callback, :string) + add(:secret, :string) + add(:valid_until, :naive_datetime) + add(:state, :string) timestamps() end diff --git a/priv/repo/migrations/20170423154511_add_fields_to_users.exs b/priv/repo/migrations/20170423154511_add_fields_to_users.exs index 84de74bc4..a079c73bd 100644 --- a/priv/repo/migrations/20170423154511_add_fields_to_users.exs +++ b/priv/repo/migrations/20170423154511_add_fields_to_users.exs @@ -3,8 +3,8 @@ defmodule Pleroma.Repo.Migrations.AddFieldsToUsers do def change do alter table(:users) do - add :local, :boolean, default: true - add :info, :map + add(:local, :boolean, default: true) + add(:info, :map) end end end diff --git a/priv/repo/migrations/20170426154155_create_websub_client_subscription.exs b/priv/repo/migrations/20170426154155_create_websub_client_subscription.exs index 4b79d7506..d020614e1 100644 --- a/priv/repo/migrations/20170426154155_create_websub_client_subscription.exs +++ b/priv/repo/migrations/20170426154155_create_websub_client_subscription.exs @@ -3,11 +3,11 @@ defmodule Pleroma.Repo.Migrations.CreateWebsubClientSubscription do def change do create_if_not_exists table(:websub_client_subscriptions) do - add :topic, :string - add :secret, :string - add :valid_until, :naive_datetime_usec - add :state, :string - add :subscribers, :map + add(:topic, :string) + add(:secret, :string) + add(:valid_until, :naive_datetime_usec) + add(:state, :string) + add(:subscribers, :map) timestamps() end diff --git a/priv/repo/migrations/20170427054757_add_user_and_hub.exs b/priv/repo/migrations/20170427054757_add_user_and_hub.exs index 4f9a520bd..f33a8572f 100644 --- a/priv/repo/migrations/20170427054757_add_user_and_hub.exs +++ b/priv/repo/migrations/20170427054757_add_user_and_hub.exs @@ -3,8 +3,8 @@ defmodule Pleroma.Repo.Migrations.AddUserAndHub do def change do alter table(:websub_client_subscriptions) do - add :hub, :string - add :user_id, references(:users) + add(:hub, :string) + add(:user_id, references(:users)) end end end diff --git a/priv/repo/migrations/20170501133231_add_id_contraints_to_activities_and_objects_part_two.exs b/priv/repo/migrations/20170501133231_add_id_contraints_to_activities_and_objects_part_two.exs index f5e5cd269..ecc7c23cc 100644 --- a/priv/repo/migrations/20170501133231_add_id_contraints_to_activities_and_objects_part_two.exs +++ b/priv/repo/migrations/20170501133231_add_id_contraints_to_activities_and_objects_part_two.exs @@ -2,10 +2,16 @@ defmodule Pleroma.Repo.Migrations.AddIdContraintsToActivitiesAndObjectsPartTwo d use Ecto.Migration def up do - drop_if_exists index(:objects, ["(data->>\"id\")"], name: :objects_unique_apid_index) - drop_if_exists index(:activities, ["(data->>\"id\")"], name: :activities_unique_apid_index) - create_if_not_exists unique_index(:objects, ["(data->>'id')"], name: :objects_unique_apid_index) - create_if_not_exists unique_index(:activities, ["(data->>'id')"], name: :activities_unique_apid_index) + drop_if_exists(index(:objects, ["(data->>\"id\")"], name: :objects_unique_apid_index)) + drop_if_exists(index(:activities, ["(data->>\"id\")"], name: :activities_unique_apid_index)) + + create_if_not_exists( + unique_index(:objects, ["(data->>'id')"], name: :objects_unique_apid_index) + ) + + create_if_not_exists( + unique_index(:activities, ["(data->>'id')"], name: :activities_unique_apid_index) + ) end def down, do: :ok diff --git a/priv/repo/migrations/20170502083023_add_local_field_to_activities.exs b/priv/repo/migrations/20170502083023_add_local_field_to_activities.exs index cebc11d21..6b61bd464 100644 --- a/priv/repo/migrations/20170502083023_add_local_field_to_activities.exs +++ b/priv/repo/migrations/20170502083023_add_local_field_to_activities.exs @@ -3,9 +3,9 @@ defmodule Pleroma.Repo.Migrations.AddLocalFieldToActivities do def change do alter table(:activities) do - add :local, :boolean, default: true + add(:local, :boolean, default: true) end - create_if_not_exists index(:activities, [:local]) + create_if_not_exists(index(:activities, [:local])) end end diff --git a/priv/repo/migrations/20170506222027_add_unique_index_to_apid.exs b/priv/repo/migrations/20170506222027_add_unique_index_to_apid.exs index 1b7e33b70..80f50029a 100644 --- a/priv/repo/migrations/20170506222027_add_unique_index_to_apid.exs +++ b/priv/repo/migrations/20170506222027_add_unique_index_to_apid.exs @@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.AddUniqueIndexToAPID do use Ecto.Migration def change do - create_if_not_exists unique_index(:users, [:ap_id]) + create_if_not_exists(unique_index(:users, [:ap_id])) end end diff --git a/priv/repo/migrations/20170529093232_longer_bios.exs b/priv/repo/migrations/20170529093232_longer_bios.exs index 9188f4bee..e25e5e144 100644 --- a/priv/repo/migrations/20170529093232_longer_bios.exs +++ b/priv/repo/migrations/20170529093232_longer_bios.exs @@ -3,14 +3,13 @@ defmodule Pleroma.Repo.Migrations.LongerBios do def up do alter table(:users) do - modify :bio, :text + modify(:bio, :text) end end def down do alter table(:users) do - modify :bio, :string + modify(:bio, :string) end end - end diff --git a/priv/repo/migrations/20170620095947_remove_activities_index.exs b/priv/repo/migrations/20170620095947_remove_activities_index.exs index e7d41eac4..ea3d4a509 100644 --- a/priv/repo/migrations/20170620095947_remove_activities_index.exs +++ b/priv/repo/migrations/20170620095947_remove_activities_index.exs @@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.RemoveActivitiesIndex do use Ecto.Migration def change do - drop_if_exists index(:activities, [:data]) + drop_if_exists(index(:activities, [:data])) end end diff --git a/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs b/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs index c95218fad..c015afbe1 100644 --- a/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs +++ b/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs @@ -2,7 +2,16 @@ defmodule Pleroma.Repo.Migrations.AddObjectActivityIndexPartTwo do use Ecto.Migration def change do - drop_if_exists index(:objects, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index) - create_if_not_exists index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index) + drop_if_exists( + index(:objects, ["(data->'object'->>'id')", "(data->>'type')"], + name: :activities_create_objects_index + ) + ) + + create_if_not_exists( + index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], + name: :activities_create_objects_index + ) + ) end end diff --git a/priv/repo/migrations/20170701142005_add_actor_index_to_activity.exs b/priv/repo/migrations/20170701142005_add_actor_index_to_activity.exs index 807fe3728..220c48abd 100644 --- a/priv/repo/migrations/20170701142005_add_actor_index_to_activity.exs +++ b/priv/repo/migrations/20170701142005_add_actor_index_to_activity.exs @@ -2,6 +2,8 @@ defmodule Pleroma.Repo.Migrations.AddActorIndexToActivity do use Ecto.Migration def change do - create_if_not_exists index(:activities, ["(data->>'actor')", "inserted_at desc"], name: :activities_actor_index) + create_if_not_exists( + index(:activities, ["(data->>'actor')", "inserted_at desc"], name: :activities_actor_index) + ) end end diff --git a/priv/repo/migrations/20170719152213_add_follower_address_to_user.exs b/priv/repo/migrations/20170719152213_add_follower_address_to_user.exs index 591164be5..be5eca36c 100644 --- a/priv/repo/migrations/20170719152213_add_follower_address_to_user.exs +++ b/priv/repo/migrations/20170719152213_add_follower_address_to_user.exs @@ -3,13 +3,13 @@ defmodule Pleroma.Repo.Migrations.AddFollowerAddressToUser do def up do alter table(:users) do - add :follower_address, :string, unique: true + add(:follower_address, :string, unique: true) end end def down do alter table(:users) do - remove :follower_address + remove(:follower_address) end end end diff --git a/priv/repo/migrations/20170906120646_add_mastodon_apps.exs b/priv/repo/migrations/20170906120646_add_mastodon_apps.exs index ccd5e3fe2..0e01625ff 100644 --- a/priv/repo/migrations/20170906120646_add_mastodon_apps.exs +++ b/priv/repo/migrations/20170906120646_add_mastodon_apps.exs @@ -3,12 +3,12 @@ defmodule Pleroma.Repo.Migrations.AddMastodonApps do def change do create_if_not_exists table(:apps) do - add :client_name, :string - add :redirect_uris, :string - add :scopes, :string - add :website, :string - add :client_id, :string - add :client_secret, :string + add(:client_name, :string) + add(:redirect_uris, :string) + add(:scopes, :string) + add(:website, :string) + add(:client_id, :string) + add(:client_secret, :string) timestamps() end diff --git a/priv/repo/migrations/20170906143140_create_o_auth_authorizations.exs b/priv/repo/migrations/20170906143140_create_o_auth_authorizations.exs index 63b25c537..9af8315a8 100644 --- a/priv/repo/migrations/20170906143140_create_o_auth_authorizations.exs +++ b/priv/repo/migrations/20170906143140_create_o_auth_authorizations.exs @@ -3,11 +3,11 @@ defmodule Pleroma.Repo.Migrations.CreateOAuthAuthorizations do def change do create_if_not_exists table(:oauth_authorizations) do - add :app_id, references(:apps) - add :user_id, references(:users) - add :token, :string - add :valid_until, :naive_datetime_usec - add :used, :boolean, default: false + add(:app_id, references(:apps)) + add(:user_id, references(:users)) + add(:token, :string) + add(:valid_until, :naive_datetime_usec) + add(:used, :boolean, default: false) timestamps() end diff --git a/priv/repo/migrations/20170906152508_create_o_auth_token.exs b/priv/repo/migrations/20170906152508_create_o_auth_token.exs index 08471bbf8..bfad98b76 100644 --- a/priv/repo/migrations/20170906152508_create_o_auth_token.exs +++ b/priv/repo/migrations/20170906152508_create_o_auth_token.exs @@ -3,11 +3,11 @@ defmodule Pleroma.Repo.Migrations.CreateOAuthToken do def change do create_if_not_exists table(:oauth_tokens) do - add :app_id, references(:apps) - add :user_id, references(:users) - add :token, :string - add :refresh_token, :string - add :valid_until, :naive_datetime_usec + add(:app_id, references(:apps)) + add(:user_id, references(:users)) + add(:token, :string) + add(:refresh_token, :string) + add(:valid_until, :naive_datetime_usec) timestamps() end diff --git a/priv/repo/migrations/20170911123607_create_notifications.exs b/priv/repo/migrations/20170911123607_create_notifications.exs index 50de9c5f1..36facc5a0 100644 --- a/priv/repo/migrations/20170911123607_create_notifications.exs +++ b/priv/repo/migrations/20170911123607_create_notifications.exs @@ -3,13 +3,13 @@ defmodule Pleroma.Repo.Migrations.CreateNotifications do def change do create_if_not_exists table(:notifications) do - add :user_id, references(:users, on_delete: :delete_all) - add :activity_id, references(:activities, on_delete: :delete_all) - add :seen, :boolean, default: false + add(:user_id, references(:users, on_delete: :delete_all)) + add(:activity_id, references(:activities, on_delete: :delete_all)) + add(:seen, :boolean, default: false) timestamps() end - create_if_not_exists index(:notifications, [:user_id]) + create_if_not_exists(index(:notifications, [:user_id])) end end diff --git a/priv/repo/migrations/20170912114248_add_context_index.exs b/priv/repo/migrations/20170912114248_add_context_index.exs index 83c585136..400a432ff 100644 --- a/priv/repo/migrations/20170912114248_add_context_index.exs +++ b/priv/repo/migrations/20170912114248_add_context_index.exs @@ -3,6 +3,11 @@ defmodule Pleroma.Repo.Migrations.AddContextIndex do @disable_ddl_transaction true def change do - create index(:activities, ["(data->>'type')", "(data->>'context')"], name: :activities_context_index, concurrently: true) + create( + index(:activities, ["(data->>'type')", "(data->>'context')"], + name: :activities_context_index, + concurrently: true + ) + ) end end diff --git a/priv/repo/migrations/20170916090107_add_fts_index_to_activities.exs b/priv/repo/migrations/20170916090107_add_fts_index_to_activities.exs index c17da8309..717e25412 100644 --- a/priv/repo/migrations/20170916090107_add_fts_index_to_activities.exs +++ b/priv/repo/migrations/20170916090107_add_fts_index_to_activities.exs @@ -3,6 +3,12 @@ defmodule Pleroma.Repo.Migrations.AddFTSIndexToActivities do @disable_ddl_transaction true def change do - create index(:activities, ["(to_tsvector('english', data->'object'->>'content'))"], concurrently: true, using: :gin, name: :activities_fts) + create( + index(:activities, ["(to_tsvector('english', data->'object'->>'content'))"], + concurrently: true, + using: :gin, + name: :activities_fts + ) + ) end end diff --git a/priv/repo/migrations/20170917120416_add_tag_index.exs b/priv/repo/migrations/20170917120416_add_tag_index.exs index d9391dda9..c69e0ef8f 100644 --- a/priv/repo/migrations/20170917120416_add_tag_index.exs +++ b/priv/repo/migrations/20170917120416_add_tag_index.exs @@ -4,6 +4,12 @@ defmodule Pleroma.Repo.Migrations.AddTagIndex do @disable_ddl_transaction true def change do - create index(:activities, ["(data #> '{\"object\",\"tag\"}')"], concurrently: true, using: :gin, name: :activities_tags) + create( + index(:activities, ["(data #> '{\"object\",\"tag\"}')"], + concurrently: true, + using: :gin, + name: :activities_tags + ) + ) end end diff --git a/priv/repo/migrations/20171019141706_create_password_reset_tokens.exs b/priv/repo/migrations/20171019141706_create_password_reset_tokens.exs index dde0f945f..2be50d15e 100644 --- a/priv/repo/migrations/20171019141706_create_password_reset_tokens.exs +++ b/priv/repo/migrations/20171019141706_create_password_reset_tokens.exs @@ -3,9 +3,9 @@ defmodule Pleroma.Repo.Migrations.CreatePasswordResetTokens do def change do create_if_not_exists table(:password_reset_tokens) do - add :token, :string - add :user_id, references(:users) - add :used, :boolean, default: false + add(:token, :string) + add(:user_id, references(:users)) + add(:used, :boolean, default: false) timestamps() end diff --git a/priv/repo/migrations/20171023155035_add_second_object_index_to_activty.exs b/priv/repo/migrations/20171023155035_add_second_object_index_to_activty.exs index c6df53ec9..261940a96 100644 --- a/priv/repo/migrations/20171023155035_add_second_object_index_to_activty.exs +++ b/priv/repo/migrations/20171023155035_add_second_object_index_to_activty.exs @@ -4,7 +4,17 @@ defmodule Pleroma.Repo.Migrations.AddSecondObjectIndexToActivty do @disable_ddl_transaction true def change do - drop_if_exists index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index) - create index(:activities, ["(coalesce(data->'object'->>'id', data->>'object'))"], name: :activities_create_objects_index, concurrently: true) + drop_if_exists( + index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], + name: :activities_create_objects_index + ) + ) + + create( + index(:activities, ["(coalesce(data->'object'->>'id', data->>'object'))"], + name: :activities_create_objects_index, + concurrently: true + ) + ) end end diff --git a/priv/repo/migrations/20171024090137_drop_object_index.exs b/priv/repo/migrations/20171024090137_drop_object_index.exs index 29b4c9333..d417577ae 100644 --- a/priv/repo/migrations/20171024090137_drop_object_index.exs +++ b/priv/repo/migrations/20171024090137_drop_object_index.exs @@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.DropObjectIndex do use Ecto.Migration def change do - drop_if_exists index(:objects, [:data], using: :gin) + drop_if_exists(index(:objects, [:data], using: :gin)) end end diff --git a/priv/repo/migrations/20171024121413_add_object_actor_index.exs b/priv/repo/migrations/20171024121413_add_object_actor_index.exs index 344c9c825..78084536c 100644 --- a/priv/repo/migrations/20171024121413_add_object_actor_index.exs +++ b/priv/repo/migrations/20171024121413_add_object_actor_index.exs @@ -4,6 +4,11 @@ defmodule Pleroma.Repo.Migrations.AddObjectActorIndex do @disable_ddl_transaction true def change do - create index(:objects, ["(data->>'actor')", "(data->>'type')"], concurrently: true, name: :objects_actor_type) + create( + index(:objects, ["(data->>'actor')", "(data->>'type')"], + concurrently: true, + name: :objects_actor_type + ) + ) end end diff --git a/priv/repo/migrations/20171109091239_add_actor_to_activity.exs b/priv/repo/migrations/20171109091239_add_actor_to_activity.exs index fb5f80c98..91348f5c3 100644 --- a/priv/repo/migrations/20171109091239_add_actor_to_activity.exs +++ b/priv/repo/migrations/20171109091239_add_actor_to_activity.exs @@ -5,16 +5,17 @@ defmodule Pleroma.Repo.Migrations.AddActorToActivity do def up do alter table(:activities) do - add :actor, :string + add(:actor, :string) end - create index(:activities, [:actor, "id DESC NULLS LAST"], concurrently: true) + create(index(:activities, [:actor, "id DESC NULLS LAST"], concurrently: true)) end def down do - drop_if_exists index(:activities, [:actor, "id DESC NULLS LAST"]) + drop_if_exists(index(:activities, [:actor, "id DESC NULLS LAST"])) + alter table(:activities) do - remove :actor + remove(:actor) end end end diff --git a/priv/repo/migrations/20171109114020_fill_actor_field.exs b/priv/repo/migrations/20171109114020_fill_actor_field.exs index 255ca46d5..fb7eca692 100644 --- a/priv/repo/migrations/20171109114020_fill_actor_field.exs +++ b/priv/repo/migrations/20171109114020_fill_actor_field.exs @@ -5,17 +5,19 @@ defmodule Pleroma.Repo.Migrations.FillActorField do def up do max = Repo.aggregate(Activity, :max, :id) + if max do IO.puts("#{max} activities") - chunks = 0..(round(max / 10_000)) + chunks = 0..round(max / 10_000) - Enum.each(chunks, fn (i) -> + Enum.each(chunks, fn i -> min = i * 10_000 max = min + 10_000 + execute(""" update activities set actor = data->>'actor' where id > #{min} and id <= #{max}; """) - |> IO.inspect + |> IO.inspect() end) end end @@ -23,4 +25,3 @@ defmodule Pleroma.Repo.Migrations.FillActorField do def down do end end - diff --git a/priv/repo/migrations/20171109141309_add_sort_index_to_activities.exs b/priv/repo/migrations/20171109141309_add_sort_index_to_activities.exs index 2d21c56ca..37fb2ce32 100644 --- a/priv/repo/migrations/20171109141309_add_sort_index_to_activities.exs +++ b/priv/repo/migrations/20171109141309_add_sort_index_to_activities.exs @@ -3,6 +3,6 @@ defmodule Pleroma.Repo.Migrations.AddSortIndexToActivities do @disable_ddl_transaction true def change do - create index(:activities, ["id desc nulls last"], concurrently: true) + create(index(:activities, ["id desc nulls last"], concurrently: true)) end end diff --git a/priv/repo/migrations/20171130135819_add_local_index_to_user.exs b/priv/repo/migrations/20171130135819_add_local_index_to_user.exs index 3438bbbc4..76bf9584e 100644 --- a/priv/repo/migrations/20171130135819_add_local_index_to_user.exs +++ b/priv/repo/migrations/20171130135819_add_local_index_to_user.exs @@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.AddLocalIndexToUser do use Ecto.Migration def change do - create_if_not_exists index(:users, [:local]) + create_if_not_exists(index(:users, [:local])) end end diff --git a/priv/repo/migrations/20171212163643_add_recipients_to_activities.exs b/priv/repo/migrations/20171212163643_add_recipients_to_activities.exs index 4520b398e..6344fbeee 100644 --- a/priv/repo/migrations/20171212163643_add_recipients_to_activities.exs +++ b/priv/repo/migrations/20171212163643_add_recipients_to_activities.exs @@ -3,9 +3,9 @@ defmodule Pleroma.Repo.Migrations.AddRecipientsToActivities do def change do alter table(:activities) do - add :recipients, {:array, :string} + add(:recipients, {:array, :string}) end - create_if_not_exists index(:activities, [:recipients], using: :gin) + create_if_not_exists(index(:activities, [:recipients], using: :gin)) end end diff --git a/priv/repo/migrations/20171212164525_fill_recipients_in_activities.exs b/priv/repo/migrations/20171212164525_fill_recipients_in_activities.exs index 87de64ca5..6dfa93716 100644 --- a/priv/repo/migrations/20171212164525_fill_recipients_in_activities.exs +++ b/priv/repo/migrations/20171212164525_fill_recipients_in_activities.exs @@ -4,17 +4,21 @@ defmodule Pleroma.Repo.Migrations.FillRecipientsInActivities do def up do max = Repo.aggregate(Activity, :max, :id) + if max do IO.puts("#{max} activities") - chunks = 0..(round(max / 10_000)) + chunks = 0..round(max / 10_000) - Enum.each(chunks, fn (i) -> + Enum.each(chunks, fn i -> min = i * 10_000 max = min + 10_000 + execute(""" - update activities set recipients = array(select jsonb_array_elements_text(data->'to')) where id > #{min} and id <= #{max}; + update activities set recipients = array(select jsonb_array_elements_text(data->'to')) where id > #{ + min + } and id <= #{max}; """) - |> IO.inspect + |> IO.inspect() end) end end diff --git a/priv/repo/migrations/20180221210540_make_following_postgres_array.exs b/priv/repo/migrations/20180221210540_make_following_postgres_array.exs index 5a8f8f669..34e94fdc8 100644 --- a/priv/repo/migrations/20180221210540_make_following_postgres_array.exs +++ b/priv/repo/migrations/20180221210540_make_following_postgres_array.exs @@ -3,17 +3,18 @@ defmodule Pleroma.Repo.Migrations.MakeFollowingPostgresArray do def up do alter table(:users) do - add :following_temp, {:array, :string} + add(:following_temp, {:array, :string}) end - execute """ + execute(""" update users set following_temp = array(select jsonb_array_elements_text(following)); - """ + """) alter table(:users) do - remove :following + remove(:following) end - rename table(:users), :following_temp, to: :following + + rename(table(:users), :following_temp, to: :following) end def down, do: :ok diff --git a/priv/repo/migrations/20180325172351_add_follower_address_index_to_users.exs b/priv/repo/migrations/20180325172351_add_follower_address_index_to_users.exs index 234d33735..18b54411c 100644 --- a/priv/repo/migrations/20180325172351_add_follower_address_index_to_users.exs +++ b/priv/repo/migrations/20180325172351_add_follower_address_index_to_users.exs @@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.AddFollowerAddressIndexToUsers do @disable_ddl_transaction true def change do - create index(:users, [:follower_address], concurrently: true) - create index(:users, [:following], concurrently: true, using: :gin) + create(index(:users, [:follower_address], concurrently: true)) + create(index(:users, [:following], concurrently: true, using: :gin)) end end diff --git a/priv/repo/migrations/20180327174350_drop_local_index_on_activities.exs b/priv/repo/migrations/20180327174350_drop_local_index_on_activities.exs index 35c4ce62f..1574e0e00 100644 --- a/priv/repo/migrations/20180327174350_drop_local_index_on_activities.exs +++ b/priv/repo/migrations/20180327174350_drop_local_index_on_activities.exs @@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.DropLocalIndexOnActivities do use Ecto.Migration def change do - drop_if_exists index(:users, [:local]) + drop_if_exists(index(:users, [:local])) end end diff --git a/priv/repo/migrations/20180327175831_actually_drop_local_index.exs b/priv/repo/migrations/20180327175831_actually_drop_local_index.exs index 7556336ed..3d52c7c80 100644 --- a/priv/repo/migrations/20180327175831_actually_drop_local_index.exs +++ b/priv/repo/migrations/20180327175831_actually_drop_local_index.exs @@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.ActuallyDropLocalIndex do use Ecto.Migration def change do - create_if_not_exists index(:users, [:local]) - drop_if_exists index("activities", :local) + create_if_not_exists(index(:users, [:local])) + drop_if_exists(index("activities", :local)) end end diff --git a/priv/repo/migrations/20180429094642_create_lists.exs b/priv/repo/migrations/20180429094642_create_lists.exs index 9d3ce50b3..e1eb7e426 100644 --- a/priv/repo/migrations/20180429094642_create_lists.exs +++ b/priv/repo/migrations/20180429094642_create_lists.exs @@ -3,13 +3,13 @@ defmodule Pleroma.Repo.Migrations.CreateLists do def change do create_if_not_exists table(:lists) do - add :user_id, references(:users, on_delete: :delete_all) - add :title, :string - add :following, {:array, :string} + add(:user_id, references(:users, on_delete: :delete_all)) + add(:title, :string) + add(:following, {:array, :string}) timestamps() end - create_if_not_exists index(:lists, [:user_id]) + create_if_not_exists(index(:lists, [:user_id])) end end diff --git a/priv/repo/migrations/20180513104714_modify_activity_index.exs b/priv/repo/migrations/20180513104714_modify_activity_index.exs index 2df530839..ec0efa238 100644 --- a/priv/repo/migrations/20180513104714_modify_activity_index.exs +++ b/priv/repo/migrations/20180513104714_modify_activity_index.exs @@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.ModifyActivityIndex do @disable_ddl_transaction true def change do - create index(:activities, ["id desc nulls last", "local"], concurrently: true) - drop_if_exists index(:activities, ["id desc nulls last"]) + create(index(:activities, ["id desc nulls last", "local"], concurrently: true)) + drop_if_exists(index(:activities, ["id desc nulls last"])) end end diff --git a/priv/repo/migrations/20180516144508_add_trigram_extension.exs b/priv/repo/migrations/20180516144508_add_trigram_extension.exs index f2f0fca86..ff0710f84 100644 --- a/priv/repo/migrations/20180516144508_add_trigram_extension.exs +++ b/priv/repo/migrations/20180516144508_add_trigram_extension.exs @@ -4,8 +4,15 @@ defmodule Pleroma.Repo.Migrations.AddTrigramExtension do def up do Logger.warn("ATTENTION ATTENTION ATTENTION\n") - Logger.warn("This will try to create the pg_trgm extension on your database. If your database user does NOT have the necessary rights, you will have to do it manually and re-run the migrations.\nYou can probably do this by running the following:\n") - Logger.warn("sudo -u postgres psql pleroma_dev -c \"create extension if not exists pg_trgm\"\n") + + Logger.warn( + "This will try to create the pg_trgm extension on your database. If your database user does NOT have the necessary rights, you will have to do it manually and re-run the migrations.\nYou can probably do this by running the following:\n" + ) + + Logger.warn( + "sudo -u postgres psql pleroma_dev -c \"create extension if not exists pg_trgm\"\n" + ) + execute("create extension if not exists pg_trgm") end diff --git a/priv/repo/migrations/20180516154905_create_user_trigram_index.exs b/priv/repo/migrations/20180516154905_create_user_trigram_index.exs index 58622a87e..0713a7297 100644 --- a/priv/repo/migrations/20180516154905_create_user_trigram_index.exs +++ b/priv/repo/migrations/20180516154905_create_user_trigram_index.exs @@ -2,6 +2,8 @@ defmodule Pleroma.Repo.Migrations.CreateUserTrigramIndex do use Ecto.Migration def change do - create_if_not_exists index(:users, ["(nickname || name) gist_trgm_ops"], name: :users_trigram_index, using: :gist) + create_if_not_exists( + index(:users, ["(nickname || name) gist_trgm_ops"], name: :users_trigram_index, using: :gist) + ) end end diff --git a/priv/repo/migrations/20180530123448_add_list_follow_index.exs b/priv/repo/migrations/20180530123448_add_list_follow_index.exs index 86b8de30a..57f8d478f 100644 --- a/priv/repo/migrations/20180530123448_add_list_follow_index.exs +++ b/priv/repo/migrations/20180530123448_add_list_follow_index.exs @@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.AddListFollowIndex do use Ecto.Migration def change do - create_if_not_exists index(:lists, [:following]) + create_if_not_exists(index(:lists, [:following])) end end diff --git a/priv/repo/migrations/20180606173637_create_apid_host_extraction_index.exs b/priv/repo/migrations/20180606173637_create_apid_host_extraction_index.exs index 9831a1b82..07b3f2875 100644 --- a/priv/repo/migrations/20180606173637_create_apid_host_extraction_index.exs +++ b/priv/repo/migrations/20180606173637_create_apid_host_extraction_index.exs @@ -3,6 +3,11 @@ defmodule Pleroma.Repo.Migrations.CreateApidHostExtractionIndex do @disable_ddl_transaction true def change do - create index(:activities, ["(split_part(actor, '/', 3))"], concurrently: true, name: :activities_hosts) + create( + index(:activities, ["(split_part(actor, '/', 3))"], + concurrently: true, + name: :activities_hosts + ) + ) end end diff --git a/priv/repo/migrations/20180612110515_create_user_invite_tokens.exs b/priv/repo/migrations/20180612110515_create_user_invite_tokens.exs index faee379f0..a75ff2a51 100644 --- a/priv/repo/migrations/20180612110515_create_user_invite_tokens.exs +++ b/priv/repo/migrations/20180612110515_create_user_invite_tokens.exs @@ -3,8 +3,8 @@ defmodule Pleroma.Repo.Migrations.CreateUserInviteTokens do def change do create_if_not_exists table(:user_invite_tokens) do - add :token, :string - add :used, :boolean, default: false + add(:token, :string) + add(:used, :boolean, default: false) timestamps() end diff --git a/priv/repo/migrations/20180617221540_create_activities_in_reply_to_index.exs b/priv/repo/migrations/20180617221540_create_activities_in_reply_to_index.exs index 1fee6fd7a..c8a0e60a0 100644 --- a/priv/repo/migrations/20180617221540_create_activities_in_reply_to_index.exs +++ b/priv/repo/migrations/20180617221540_create_activities_in_reply_to_index.exs @@ -3,6 +3,11 @@ defmodule Pleroma.Repo.Migrations.CreateActivitiesInReplyToIndex do @disable_ddl_transaction true def change do - create index(:activities, ["(data->'object'->>'inReplyTo')"], concurrently: true, name: :activities_in_reply_to) + create( + index(:activities, ["(data->'object'->>'inReplyTo')"], + concurrently: true, + name: :activities_in_reply_to + ) + ) end end diff --git a/priv/repo/migrations/20180813003722_create_filters.exs b/priv/repo/migrations/20180813003722_create_filters.exs index 541cf46a1..7803558df 100644 --- a/priv/repo/migrations/20180813003722_create_filters.exs +++ b/priv/repo/migrations/20180813003722_create_filters.exs @@ -3,18 +3,21 @@ defmodule Pleroma.Repo.Migrations.CreateFilters do def change do create_if_not_exists table(:filters) do - add :user_id, references(:users, on_delete: :delete_all) - add :filter_id, :integer - add :hide, :boolean - add :phrase, :string - add :context, {:array, :string} - add :expires_at, :utc_datetime - add :whole_word, :boolean + add(:user_id, references(:users, on_delete: :delete_all)) + add(:filter_id, :integer) + add(:hide, :boolean) + add(:phrase, :string) + add(:context, {:array, :string}) + add(:expires_at, :utc_datetime) + add(:whole_word, :boolean) timestamps() end - create_if_not_exists index(:filters, [:user_id]) - create_if_not_exists index(:filters, [:phrase], where: "hide = true", name: :hided_phrases_index) + create_if_not_exists(index(:filters, [:user_id])) + + create_if_not_exists( + index(:filters, [:phrase], where: "hide = true", name: :hided_phrases_index) + ) end end diff --git a/priv/repo/migrations/20180829082446_add_recipients_to_and_cc_fields_to_activities.exs b/priv/repo/migrations/20180829082446_add_recipients_to_and_cc_fields_to_activities.exs index af9d521c0..481986039 100644 --- a/priv/repo/migrations/20180829082446_add_recipients_to_and_cc_fields_to_activities.exs +++ b/priv/repo/migrations/20180829082446_add_recipients_to_and_cc_fields_to_activities.exs @@ -3,11 +3,11 @@ defmodule Pleroma.Repo.Migrations.AddRecipientsToAndCcFieldsToActivities do def change do alter table(:activities) do - add :recipients_to, {:array, :string} - add :recipients_cc, {:array, :string} + add(:recipients_to, {:array, :string}) + add(:recipients_cc, {:array, :string}) end - create_if_not_exists index(:activities, [:recipients_to], using: :gin) - create_if_not_exists index(:activities, [:recipients_cc], using: :gin) + create_if_not_exists(index(:activities, [:recipients_to], using: :gin)) + create_if_not_exists(index(:activities, [:recipients_cc], using: :gin)) end end diff --git a/priv/repo/migrations/20180829182612_activities_add_to_cc_indices.exs b/priv/repo/migrations/20180829182612_activities_add_to_cc_indices.exs index 9d31f6779..1f9f97861 100644 --- a/priv/repo/migrations/20180829182612_activities_add_to_cc_indices.exs +++ b/priv/repo/migrations/20180829182612_activities_add_to_cc_indices.exs @@ -2,7 +2,12 @@ defmodule Pleroma.Repo.Migrations.ActivitiesAddToCcIndices do use Ecto.Migration def change do - create_if_not_exists index(:activities, ["(data->'to')"], name: :activities_to_index, using: :gin) - create_if_not_exists index(:activities, ["(data->'cc')"], name: :activities_cc_index, using: :gin) + create_if_not_exists( + index(:activities, ["(data->'to')"], name: :activities_to_index, using: :gin) + ) + + create_if_not_exists( + index(:activities, ["(data->'cc')"], name: :activities_cc_index, using: :gin) + ) end end diff --git a/priv/repo/migrations/20180829183529_remove_recipients_to_and_cc_fields_from_activities.exs b/priv/repo/migrations/20180829183529_remove_recipients_to_and_cc_fields_from_activities.exs index 017ef161f..65576b8d5 100644 --- a/priv/repo/migrations/20180829183529_remove_recipients_to_and_cc_fields_from_activities.exs +++ b/priv/repo/migrations/20180829183529_remove_recipients_to_and_cc_fields_from_activities.exs @@ -3,15 +3,15 @@ defmodule Pleroma.Repo.Migrations.RemoveRecipientsToAndCcFieldsFromActivities do def up do alter table(:activities) do - remove :recipients_to - remove :recipients_cc + remove(:recipients_to) + remove(:recipients_cc) end end def down do alter table(:activities) do - add :recipients_to, {:array, :string} - add :recipients_cc, {:array, :string} + add(:recipients_to, {:array, :string}) + add(:recipients_cc, {:array, :string}) end end end diff --git a/priv/repo/migrations/20180903114437_users_add_is_moderator_index.exs b/priv/repo/migrations/20180903114437_users_add_is_moderator_index.exs index adce28bdf..cbe79de05 100644 --- a/priv/repo/migrations/20180903114437_users_add_is_moderator_index.exs +++ b/priv/repo/migrations/20180903114437_users_add_is_moderator_index.exs @@ -2,6 +2,8 @@ defmodule Pleroma.Repo.Migrations.UsersAddIsModeratorIndex do use Ecto.Migration def change do - create_if_not_exists index(:users, ["(info->'is_moderator')"], name: :users_is_moderator_index, using: :gin) + create_if_not_exists( + index(:users, ["(info->'is_moderator')"], name: :users_is_moderator_index, using: :gin) + ) end end diff --git a/priv/repo/migrations/20180918182427_create_push_subscriptions.exs b/priv/repo/migrations/20180918182427_create_push_subscriptions.exs index 36bdf322a..c1b55d018 100644 --- a/priv/repo/migrations/20180918182427_create_push_subscriptions.exs +++ b/priv/repo/migrations/20180918182427_create_push_subscriptions.exs @@ -3,16 +3,16 @@ defmodule Pleroma.Repo.Migrations.CreatePushSubscriptions do def change do create_if_not_exists table("push_subscriptions") do - add :user_id, references("users", on_delete: :delete_all) - add :token_id, references("oauth_tokens", on_delete: :delete_all) - add :endpoint, :string - add :key_p256dh, :string - add :key_auth, :string - add :data, :map + add(:user_id, references("users", on_delete: :delete_all)) + add(:token_id, references("oauth_tokens", on_delete: :delete_all)) + add(:endpoint, :string) + add(:key_p256dh, :string) + add(:key_auth, :string) + add(:data, :map) timestamps() end - create_if_not_exists index("push_subscriptions", [:user_id, :token_id], unique: true) + create_if_not_exists(index("push_subscriptions", [:user_id, :token_id], unique: true)) end end diff --git a/priv/repo/migrations/20180919060348_users_add_last_refreshed_at.exs b/priv/repo/migrations/20180919060348_users_add_last_refreshed_at.exs index 815177e05..16605cf7b 100644 --- a/priv/repo/migrations/20180919060348_users_add_last_refreshed_at.exs +++ b/priv/repo/migrations/20180919060348_users_add_last_refreshed_at.exs @@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.UsersAddLastRefreshedAt do def change do alter table(:users) do - add :last_refreshed_at, :naive_datetime_usec + add(:last_refreshed_at, :naive_datetime_usec) end end end diff --git a/priv/repo/migrations/20181206125616_add_tags_to_users.exs b/priv/repo/migrations/20181206125616_add_tags_to_users.exs index 7d42a0fba..a46c0fc35 100644 --- a/priv/repo/migrations/20181206125616_add_tags_to_users.exs +++ b/priv/repo/migrations/20181206125616_add_tags_to_users.exs @@ -3,9 +3,9 @@ defmodule Pleroma.Repo.Migrations.AddTagsToUsers do def change do alter table(:users) do - add :tags, {:array, :string} + add(:tags, {:array, :string}) end - create_if_not_exists index(:users, [:tags], using: :gin) + create_if_not_exists(index(:users, [:tags], using: :gin)) end end diff --git a/priv/repo/migrations/20181214121049_add_bookmarks_to_users.exs b/priv/repo/migrations/20181214121049_add_bookmarks_to_users.exs index 55e97ae0e..6228f1bad 100644 --- a/priv/repo/migrations/20181214121049_add_bookmarks_to_users.exs +++ b/priv/repo/migrations/20181214121049_add_bookmarks_to_users.exs @@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.AddBookmarksToUsers do def change do alter table(:users) do - add :bookmarks, {:array, :string}, null: false, default: [] + add(:bookmarks, {:array, :string}, null: false, default: []) end end end diff --git a/priv/repo/migrations/20181218172826_users_and_activities_flake_id.exs b/priv/repo/migrations/20181218172826_users_and_activities_flake_id.exs index a5b4c543d..c58d829af 100644 --- a/priv/repo/migrations/20181218172826_users_and_activities_flake_id.exs +++ b/priv/repo/migrations/20181218172826_users_and_activities_flake_id.exs @@ -16,32 +16,34 @@ defmodule Pleroma.Repo.Migrations.UsersAndActivitiesFlakeId do # Old serial int ids are transformed to 128bits with extra padding. # The application (in `Pleroma.FlakeId`) handles theses IDs properly as integers; to keep compatibility # with previously issued ids. - #execute "update activities set external_id = CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);" - #execute "update users set external_id = CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);" + # execute "update activities set external_id = CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);" + # execute "update users set external_id = CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);" clippy = start_clippy_heartbeats() # Lock both tables to avoid a running server to meddling with our transaction - execute "LOCK TABLE activities;" - execute "LOCK TABLE users;" + execute("LOCK TABLE activities;") + execute("LOCK TABLE users;") - execute """ + execute(""" ALTER TABLE activities DROP CONSTRAINT activities_pkey CASCADE, ALTER COLUMN id DROP default, ALTER COLUMN id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid), ADD PRIMARY KEY (id); - """ + """) - execute """ + execute(""" ALTER TABLE users DROP CONSTRAINT users_pkey CASCADE, ALTER COLUMN id DROP default, ALTER COLUMN id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid), ADD PRIMARY KEY (id); - """ + """) - execute "UPDATE users SET info = jsonb_set(info, '{pinned_activities}', array_to_json(ARRAY(select jsonb_array_elements_text(info->'pinned_activities')))::jsonb);" + execute( + "UPDATE users SET info = jsonb_set(info, '{pinned_activities}', array_to_json(ARRAY(select jsonb_array_elements_text(info->'pinned_activities')))::jsonb);" + ) # Fkeys: # Activities - Referenced by: @@ -56,18 +58,19 @@ defmodule Pleroma.Repo.Migrations.UsersAndActivitiesFlakeId do # TABLE "push_subscriptions" CONSTRAINT "push_subscriptions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE # TABLE "websub_client_subscriptions" CONSTRAINT "websub_client_subscriptions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) - execute """ + execute(""" ALTER TABLE notifications ALTER COLUMN activity_id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(activity_id), 32, '0' ) AS uuid), ADD CONSTRAINT notifications_activity_id_fkey FOREIGN KEY (activity_id) REFERENCES activities(id) ON DELETE CASCADE; - """ + """) - for table <- ~w(notifications filters lists oauth_authorizations oauth_tokens password_reset_tokens push_subscriptions websub_client_subscriptions) do - execute """ + for table <- + ~w(notifications filters lists oauth_authorizations oauth_tokens password_reset_tokens push_subscriptions websub_client_subscriptions) do + execute(""" ALTER TABLE #{table} ALTER COLUMN user_id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(user_id), 32, '0' ) AS uuid), ADD CONSTRAINT #{table}_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; - """ + """) end flush() @@ -78,41 +81,50 @@ defmodule Pleroma.Repo.Migrations.UsersAndActivitiesFlakeId do def down, do: :ok defp start_clippy_heartbeats() do - count = from(a in "activities", select: count(a.id)) |> Repo.one! + count = from(a in "activities", select: count(a.id)) |> Repo.one!() if count > 5000 do heartbeat_interval = :timer.minutes(2) + :timer.seconds(30) - all_tips = Clippy.tips() ++ [ - "The migration is still running, maybe it's time for another “tea”?", - "Happy rabbits practice a cute behavior known as a\n“binky:” they jump up in the air\nand twist\nand spin around!", - "Nothing and everything.\n\nI still work.", - "Pleroma runs on a Raspberry Pi!\n\n … but this migration will take forever if you\nactually run on a raspberry pi", - "Status? Stati? Post? Note? Toot?\nRepeat? Reboost? Boost? Retweet? Retoot??\n\nI-I'm confused.", - ] - heartbeat = fn(heartbeat, runs, all_tips, tips) -> - tips = if Integer.is_even(runs) do - tips = if tips == [], do: all_tips, else: tips - [tip | tips] = Enum.shuffle(tips) - Clippy.puts(tip) - tips - else - IO.puts "\n -- #{DateTime.to_string(DateTime.utc_now())} Migration still running, please wait…\n" - tips - end + all_tips = + Clippy.tips() ++ + [ + "The migration is still running, maybe it's time for another “tea”?", + "Happy rabbits practice a cute behavior known as a\n“binky:” they jump up in the air\nand twist\nand spin around!", + "Nothing and everything.\n\nI still work.", + "Pleroma runs on a Raspberry Pi!\n\n … but this migration will take forever if you\nactually run on a raspberry pi", + "Status? Stati? Post? Note? Toot?\nRepeat? Reboost? Boost? Retweet? Retoot??\n\nI-I'm confused." + ] + + heartbeat = fn heartbeat, runs, all_tips, tips -> + tips = + if Integer.is_even(runs) do + tips = if tips == [], do: all_tips, else: tips + [tip | tips] = Enum.shuffle(tips) + Clippy.puts(tip) + tips + else + IO.puts( + "\n -- #{DateTime.to_string(DateTime.utc_now())} Migration still running, please wait…\n" + ) + + tips + end + :timer.sleep(heartbeat_interval) heartbeat.(heartbeat, runs + 1, all_tips, tips) end - Clippy.puts [ + Clippy.puts([ [:red, :bright, "It looks like you are running an older instance!"], [""], [:bright, "This migration may take a long time", :reset, " -- so you probably should"], ["go drink a cofe, or a tea, or a beer, a whiskey, a vodka,"], ["while it runs to deal with your temporary fediverse pause!"] - ] + ]) + :timer.sleep(heartbeat_interval) - spawn_link(fn() -> heartbeat.(heartbeat, 1, all_tips, []) end) + spawn_link(fn -> heartbeat.(heartbeat, 1, all_tips, []) end) end end @@ -120,8 +132,7 @@ defmodule Pleroma.Repo.Migrations.UsersAndActivitiesFlakeId do if pid do Process.unlink(pid) Process.exit(pid, :kill) - Clippy.puts [[:green, :bright, "Hurray!!", "", "", "Migration completed!"]] + Clippy.puts([[:green, :bright, "Hurray!!", "", "", "Migration completed!"]]) end end - end diff --git a/priv/repo/migrations/20190109152453_add_visibility_function.exs b/priv/repo/migrations/20190109152453_add_visibility_function.exs index b6a4e752b..43d1074aa 100644 --- a/priv/repo/migrations/20190109152453_add_visibility_function.exs +++ b/priv/repo/migrations/20190109152453_add_visibility_function.exs @@ -43,6 +43,8 @@ defmodule Pleroma.Repo.Migrations.AddVisibilityFunction do ) ) - execute("drop function if exists activity_visibility(actor varchar, recipients varchar[], data jsonb)") + execute( + "drop function if exists activity_visibility(actor varchar, recipients varchar[], data jsonb)" + ) end end diff --git a/priv/repo/migrations/20190115085500_create_user_fts_index.exs b/priv/repo/migrations/20190115085500_create_user_fts_index.exs index cff975318..0c0c512d3 100644 --- a/priv/repo/migrations/20190115085500_create_user_fts_index.exs +++ b/priv/repo/migrations/20190115085500_create_user_fts_index.exs @@ -2,16 +2,18 @@ defmodule Pleroma.Repo.Migrations.CreateUserFtsIndex do use Ecto.Migration def change do - create_if_not_exists index( - :users, - [ - """ - (setweight(to_tsvector('simple', regexp_replace(nickname, '\\W', ' ', 'g')), 'A') || - setweight(to_tsvector('simple', regexp_replace(coalesce(name, ''), '\\W', ' ', 'g')), 'B')) - """ - ], - name: :users_fts_index, - using: :gin - ) + create_if_not_exists( + index( + :users, + [ + """ + (setweight(to_tsvector('simple', regexp_replace(nickname, '\\W', ' ', 'g')), 'A') || + setweight(to_tsvector('simple', regexp_replace(coalesce(name, ''), '\\W', ' ', 'g')), 'B')) + """ + ], + name: :users_fts_index, + using: :gin + ) + ) end end diff --git a/priv/repo/migrations/20190122153157_update_activity_visibility.exs b/priv/repo/migrations/20190122153157_update_activity_visibility.exs index 30075137c..9e29571ee 100644 --- a/priv/repo/migrations/20190122153157_update_activity_visibility.exs +++ b/priv/repo/migrations/20190122153157_update_activity_visibility.exs @@ -27,10 +27,8 @@ defmodule Pleroma.Repo.Migrations.UpdateActivityVisibility do """ execute(definition) - end def down do - end end diff --git a/priv/repo/migrations/20190123092341_users_add_is_admin_index.exs b/priv/repo/migrations/20190123092341_users_add_is_admin_index.exs index 25f248c59..f42d46427 100644 --- a/priv/repo/migrations/20190123092341_users_add_is_admin_index.exs +++ b/priv/repo/migrations/20190123092341_users_add_is_admin_index.exs @@ -2,6 +2,8 @@ defmodule Pleroma.Repo.Migrations.UsersAddIsAdminIndex do use Ecto.Migration def change do - create_if_not_exists(index(:users, ["(info->'is_admin')"], name: :users_is_admin_index, using: :gin)) + create_if_not_exists( + index(:users, ["(info->'is_admin')"], name: :users_is_admin_index, using: :gin) + ) end end diff --git a/priv/repo/migrations/20190123125546_create_instances.exs b/priv/repo/migrations/20190123125546_create_instances.exs index a9b356bc3..9438736ba 100644 --- a/priv/repo/migrations/20190123125546_create_instances.exs +++ b/priv/repo/migrations/20190123125546_create_instances.exs @@ -3,13 +3,13 @@ defmodule Pleroma.Repo.Migrations.CreateInstances do def change do create_if_not_exists table(:instances) do - add :host, :string - add :unreachable_since, :naive_datetime_usec + add(:host, :string) + add(:unreachable_since, :naive_datetime_usec) timestamps() end - create_if_not_exists unique_index(:instances, [:host]) - create_if_not_exists index(:instances, [:unreachable_since]) + create_if_not_exists(unique_index(:instances, [:host])) + create_if_not_exists(index(:instances, [:unreachable_since])) end end diff --git a/priv/repo/migrations/20190124131141_update_activity_visibility_again.exs b/priv/repo/migrations/20190124131141_update_activity_visibility_again.exs index 0519a5143..a42e4cad9 100644 --- a/priv/repo/migrations/20190124131141_update_activity_visibility_again.exs +++ b/priv/repo/migrations/20190124131141_update_activity_visibility_again.exs @@ -27,11 +27,8 @@ defmodule Pleroma.Repo.Migrations.UpdateActivityVisibilityAgain do """ execute(definition) - end def down do - end - end diff --git a/priv/repo/migrations/20190127151220_add_activities_likes_index.exs b/priv/repo/migrations/20190127151220_add_activities_likes_index.exs index b1822d265..115b12491 100644 --- a/priv/repo/migrations/20190127151220_add_activities_likes_index.exs +++ b/priv/repo/migrations/20190127151220_add_activities_likes_index.exs @@ -3,6 +3,12 @@ defmodule Pleroma.Repo.Migrations.AddActivitiesLikesIndex do @disable_ddl_transaction true def change do - create index(:activities, ["((data #> '{\"object\",\"likes\"}'))"], concurrently: true, name: :activities_likes, using: :gin) + create( + index(:activities, ["((data #> '{\"object\",\"likes\"}'))"], + concurrently: true, + name: :activities_likes, + using: :gin + ) + ) end end diff --git a/priv/repo/migrations/20190203185340_split_hide_network.exs b/priv/repo/migrations/20190203185340_split_hide_network.exs index 8b7a9151b..fb677f68a 100644 --- a/priv/repo/migrations/20190203185340_split_hide_network.exs +++ b/priv/repo/migrations/20190203185340_split_hide_network.exs @@ -2,9 +2,17 @@ defmodule Pleroma.Repo.Migrations.SplitHideNetwork do use Ecto.Migration def up do - execute("UPDATE users SET info = jsonb_set(info, '{hide_network}'::text[], 'false'::jsonb) WHERE NOT(info::jsonb ? 'hide_network') AND local") - execute("UPDATE users SET info = jsonb_set(info, '{hide_followings}'::text[], info->'hide_network') WHERE local") - execute("UPDATE users SET info = jsonb_set(info, '{hide_followers}'::text[], info->'hide_network') WHERE local") + execute( + "UPDATE users SET info = jsonb_set(info, '{hide_network}'::text[], 'false'::jsonb) WHERE NOT(info::jsonb ? 'hide_network') AND local" + ) + + execute( + "UPDATE users SET info = jsonb_set(info, '{hide_followings}'::text[], info->'hide_network') WHERE local" + ) + + execute( + "UPDATE users SET info = jsonb_set(info, '{hide_followers}'::text[], info->'hide_network') WHERE local" + ) end def down do diff --git a/priv/repo/migrations/20190205114625_create_thread_mutes.exs b/priv/repo/migrations/20190205114625_create_thread_mutes.exs index baaf07253..df9eb7677 100644 --- a/priv/repo/migrations/20190205114625_create_thread_mutes.exs +++ b/priv/repo/migrations/20190205114625_create_thread_mutes.exs @@ -3,10 +3,10 @@ defmodule Pleroma.Repo.Migrations.CreateThreadMutes do def change do create_if_not_exists table(:thread_mutes) do - add :user_id, references(:users, type: :uuid, on_delete: :delete_all) - add :context, :string + add(:user_id, references(:users, type: :uuid, on_delete: :delete_all)) + add(:context, :string) end - create_if_not_exists unique_index(:thread_mutes, [:user_id, :context], name: :unique_index) + create_if_not_exists(unique_index(:thread_mutes, [:user_id, :context], name: :unique_index)) end end diff --git a/priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs b/priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs index 4efbebc4d..ad93bfce2 100644 --- a/priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs +++ b/priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs @@ -4,7 +4,7 @@ defmodule Pleroma.Repo.Migrations.AddScopeSToOAuthEntities do def change do for t <- [:oauth_authorizations, :oauth_tokens] do alter table(t) do - add :scopes, {:array, :string}, default: [], null: false + add(:scopes, {:array, :string}, default: [], null: false) end end end diff --git a/priv/repo/migrations/20190213185503_change_apps_scopes_to_varchar_array.exs b/priv/repo/migrations/20190213185503_change_apps_scopes_to_varchar_array.exs index 72decd401..eb6fcb012 100644 --- a/priv/repo/migrations/20190213185503_change_apps_scopes_to_varchar_array.exs +++ b/priv/repo/migrations/20190213185503_change_apps_scopes_to_varchar_array.exs @@ -4,14 +4,20 @@ defmodule Pleroma.Repo.Migrations.ChangeAppsScopesToVarcharArray do @alter_apps_scopes "ALTER TABLE apps ALTER COLUMN scopes" def up do - execute "#{@alter_apps_scopes} TYPE varchar(255)[] USING string_to_array(scopes, ',')::varchar(255)[];" - execute "#{@alter_apps_scopes} SET DEFAULT ARRAY[]::character varying[];" - execute "#{@alter_apps_scopes} SET NOT NULL;" + execute( + "#{@alter_apps_scopes} TYPE varchar(255)[] USING string_to_array(scopes, ',')::varchar(255)[];" + ) + + execute("#{@alter_apps_scopes} SET DEFAULT ARRAY[]::character varying[];") + execute("#{@alter_apps_scopes} SET NOT NULL;") end def down do - execute "#{@alter_apps_scopes} DROP NOT NULL;" - execute "#{@alter_apps_scopes} DROP DEFAULT;" - execute "#{@alter_apps_scopes} TYPE varchar(255) USING array_to_string(scopes, ',')::varchar(255);" + execute("#{@alter_apps_scopes} DROP NOT NULL;") + execute("#{@alter_apps_scopes} DROP DEFAULT;") + + execute( + "#{@alter_apps_scopes} TYPE varchar(255) USING array_to_string(scopes, ',')::varchar(255);" + ) end end diff --git a/priv/repo/migrations/20190213185600_data_migration_populate_o_auth_scopes.exs b/priv/repo/migrations/20190213185600_data_migration_populate_o_auth_scopes.exs index 7afbcbd76..ef5b35125 100644 --- a/priv/repo/migrations/20190213185600_data_migration_populate_o_auth_scopes.exs +++ b/priv/repo/migrations/20190213185600_data_migration_populate_o_auth_scopes.exs @@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.DataMigrationPopulateOAuthScopes do def up do for t <- [:oauth_authorizations, :oauth_tokens] do - execute "UPDATE #{t} SET scopes = apps.scopes FROM apps WHERE #{t}.app_id = apps.id;" + execute("UPDATE #{t} SET scopes = apps.scopes FROM apps WHERE #{t}.app_id = apps.id;") end end diff --git a/priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs b/priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs index d44e5096b..92ab9bd2c 100644 --- a/priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs +++ b/priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs @@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.DataMigrationNormalizeScopes do def up do for t <- [:apps, :oauth_authorizations, :oauth_tokens] do - execute "UPDATE #{t} SET scopes = string_to_array(array_to_string(scopes, ' '), ' ');" + execute("UPDATE #{t} SET scopes = string_to_array(array_to_string(scopes, ' '), ' ');") end end diff --git a/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs b/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs index faeb8f1c6..ea0947852 100644 --- a/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs +++ b/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs @@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.AddDefaultTagsToUser do use Ecto.Migration def up do - execute "UPDATE users SET tags = array[]::varchar[] where tags IS NULL" + execute("UPDATE users SET tags = array[]::varchar[] where tags IS NULL") end def down, do: :noop diff --git a/priv/repo/migrations/20190303120636_update_user_note_counters.exs b/priv/repo/migrations/20190303120636_update_user_note_counters.exs index 54e68f7c9..95dbd012f 100644 --- a/priv/repo/migrations/20190303120636_update_user_note_counters.exs +++ b/priv/repo/migrations/20190303120636_update_user_note_counters.exs @@ -4,7 +4,7 @@ defmodule Pleroma.Repo.Migrations.UpdateUserNoteCounters do @public "https://www.w3.org/ns/activitystreams#Public" def up do - execute """ + execute(""" WITH public_note_count AS ( SELECT data->>'actor' AS actor, @@ -19,11 +19,11 @@ defmodule Pleroma.Repo.Migrations.UpdateUserNoteCounters do SET "info" = jsonb_set(u.info, '{note_count}', o.count::varchar::jsonb, true) FROM public_note_count AS o WHERE u.ap_id = o.actor - """ + """) end def down do - execute """ + execute(""" WITH public_note_count AS ( SELECT data->>'actor' AS actor, @@ -36,6 +36,6 @@ defmodule Pleroma.Repo.Migrations.UpdateUserNoteCounters do SET "info" = jsonb_set(u.info, '{note_count}', o.count::varchar::jsonb, true) FROM public_note_count AS o WHERE u.ap_id = o.actor - """ + """) end end diff --git a/priv/repo/migrations/20190315101315_create_registrations.exs b/priv/repo/migrations/20190315101315_create_registrations.exs index 34a390a93..d705a499e 100644 --- a/priv/repo/migrations/20190315101315_create_registrations.exs +++ b/priv/repo/migrations/20190315101315_create_registrations.exs @@ -3,16 +3,16 @@ defmodule Pleroma.Repo.Migrations.CreateRegistrations do def change do create_if_not_exists table(:registrations, primary_key: false) do - add :id, :uuid, primary_key: true - add :user_id, references(:users, type: :uuid, on_delete: :delete_all) - add :provider, :string - add :uid, :string - add :info, :map, default: %{} + add(:id, :uuid, primary_key: true) + add(:user_id, references(:users, type: :uuid, on_delete: :delete_all)) + add(:provider, :string) + add(:uid, :string) + add(:info, :map, default: %{}) timestamps() end - create_if_not_exists unique_index(:registrations, [:provider, :uid]) - create_if_not_exists unique_index(:registrations, [:user_id, :provider, :uid]) + create_if_not_exists(unique_index(:registrations, [:provider, :uid])) + create_if_not_exists(unique_index(:registrations, [:user_id, :provider, :uid])) end end diff --git a/priv/repo/migrations/20190325185009_create_notification_id_index.exs b/priv/repo/migrations/20190325185009_create_notification_id_index.exs index 01cb30559..7209c16a9 100644 --- a/priv/repo/migrations/20190325185009_create_notification_id_index.exs +++ b/priv/repo/migrations/20190325185009_create_notification_id_index.exs @@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.CreateNotificationIdIndex do use Ecto.Migration def change do - create_if_not_exists index(:notifications, ["id desc nulls last"]) + create_if_not_exists(index(:notifications, ["id desc nulls last"])) end end diff --git a/priv/repo/migrations/20190405160700_add_index_on_subscribers.exs b/priv/repo/migrations/20190405160700_add_index_on_subscribers.exs index 460dafb1b..bbf47f72c 100644 --- a/priv/repo/migrations/20190405160700_add_index_on_subscribers.exs +++ b/priv/repo/migrations/20190405160700_add_index_on_subscribers.exs @@ -3,6 +3,12 @@ defmodule Pleroma.Repo.Migrations.AddIndexOnSubscribers do @disable_ddl_transaction true def change do - create index(:users, ["(info->'subscribers')"], name: :users_subscribers_index, using: :gin, concurrently: true) + create( + index(:users, ["(info->'subscribers')"], + name: :users_subscribers_index, + using: :gin, + concurrently: true + ) + ) end end diff --git a/priv/repo/migrations/20190408123347_create_conversations.exs b/priv/repo/migrations/20190408123347_create_conversations.exs index 7b7d89da7..d75459e82 100644 --- a/priv/repo/migrations/20190408123347_create_conversations.exs +++ b/priv/repo/migrations/20190408123347_create_conversations.exs @@ -19,8 +19,8 @@ defmodule Pleroma.Repo.Migrations.CreateConversations do timestamps() end - create_if_not_exists index(:conversation_participations, [:conversation_id]) - create_if_not_exists unique_index(:conversation_participations, [:user_id, :conversation_id]) - create_if_not_exists unique_index(:conversations, [:ap_id]) + create_if_not_exists(index(:conversation_participations, [:conversation_id])) + create_if_not_exists(unique_index(:conversation_participations, [:user_id, :conversation_id])) + create_if_not_exists(unique_index(:conversations, [:ap_id])) end end diff --git a/priv/repo/migrations/20190410152859_add_participation_updated_at_index.exs b/priv/repo/migrations/20190410152859_add_participation_updated_at_index.exs index b5ca2fc0f..e22c6e57d 100644 --- a/priv/repo/migrations/20190410152859_add_participation_updated_at_index.exs +++ b/priv/repo/migrations/20190410152859_add_participation_updated_at_index.exs @@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.AddParticipationUpdatedAtIndex do use Ecto.Migration def change do - create_if_not_exists index(:conversation_participations, ["updated_at desc"]) + create_if_not_exists(index(:conversation_participations, ["updated_at desc"])) end end diff --git a/priv/repo/migrations/20190411094120_add_index_on_user_info_deactivated.exs b/priv/repo/migrations/20190411094120_add_index_on_user_info_deactivated.exs index c19427f12..374e2323d 100644 --- a/priv/repo/migrations/20190411094120_add_index_on_user_info_deactivated.exs +++ b/priv/repo/migrations/20190411094120_add_index_on_user_info_deactivated.exs @@ -2,6 +2,8 @@ defmodule Pleroma.Repo.Migrations.AddIndexOnUserInfoDeactivated do use Ecto.Migration def change do - create_if_not_exists(index(:users, ["(info->'deactivated')"], name: :users_deactivated_index, using: :gin)) + create_if_not_exists( + index(:users, ["(info->'deactivated')"], name: :users_deactivated_index, using: :gin) + ) end end diff --git a/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs b/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs index ce4590954..f3928a149 100644 --- a/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs +++ b/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs @@ -18,7 +18,7 @@ defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do |> Enum.each(fn %{id: user_id, bookmarks: bookmarks} -> Enum.each(bookmarks, fn ap_id -> activity = Activity.get_create_by_object_ap_id(ap_id) - unless is_nil(activity), do: {:ok, _} = Bookmark.create(user_id, activity.id) + unless is_nil(activity), do: {:ok, _} = Bookmark.create(user_id, activity.id) end) end) @@ -29,7 +29,7 @@ defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do def down do alter table(:users) do - add :bookmarks, {:array, :string}, null: false, default: [] + add(:bookmarks, {:array, :string}, null: false, default: []) end end end diff --git a/priv/repo/migrations/20190501125843_add_fts_index_to_objects.exs b/priv/repo/migrations/20190501125843_add_fts_index_to_objects.exs index d4de51691..41630bace 100644 --- a/priv/repo/migrations/20190501125843_add_fts_index_to_objects.exs +++ b/priv/repo/migrations/20190501125843_add_fts_index_to_objects.exs @@ -2,7 +2,18 @@ defmodule Pleroma.Repo.Migrations.AddFTSIndexToObjects do use Ecto.Migration def change do - drop_if_exists index(:activities, ["(to_tsvector('english', data->'object'->>'content'))"], using: :gin, name: :activities_fts) - create_if_not_exists index(:objects, ["(to_tsvector('english', data->>'content'))"], using: :gin, name: :objects_fts) + drop_if_exists( + index(:activities, ["(to_tsvector('english', data->'object'->>'content'))"], + using: :gin, + name: :activities_fts + ) + ) + + create_if_not_exists( + index(:objects, ["(to_tsvector('english', data->>'content'))"], + using: :gin, + name: :objects_fts + ) + ) end end diff --git a/priv/repo/migrations/20190511191044_set_default_state_to_reports.exs b/priv/repo/migrations/20190511191044_set_default_state_to_reports.exs index 0d3d253b6..ab1351d56 100644 --- a/priv/repo/migrations/20190511191044_set_default_state_to_reports.exs +++ b/priv/repo/migrations/20190511191044_set_default_state_to_reports.exs @@ -2,18 +2,18 @@ defmodule Pleroma.Repo.Migrations.SetDefaultStateToReports do use Ecto.Migration def up do - execute """ + execute(""" UPDATE activities AS a SET data = jsonb_set(data, '{state}', '"open"', true) WHERE data->>'type' = 'Flag' - """ + """) end def down do - execute """ + execute(""" UPDATE activities AS a SET data = data #- '{state}' WHERE data->>'type' = 'Flag' - """ + """) end end diff --git a/priv/repo/migrations/20190513175809_change_hide_column_in_filter_table.exs b/priv/repo/migrations/20190513175809_change_hide_column_in_filter_table.exs index 246b70cfb..8135ab178 100644 --- a/priv/repo/migrations/20190513175809_change_hide_column_in_filter_table.exs +++ b/priv/repo/migrations/20190513175809_change_hide_column_in_filter_table.exs @@ -3,13 +3,13 @@ defmodule Pleroma.Repo.Migrations.ChangeHideColumnInFilterTable do def up do alter table(:filters) do - modify :hide, :boolean, default: false + modify(:hide, :boolean, default: false) end end def down do alter table(:filters) do - modify :hide, :boolean + modify(:hide, :boolean) end end end diff --git a/priv/repo/migrations/20190603162018_add_object_in_reply_to_index.exs b/priv/repo/migrations/20190603162018_add_object_in_reply_to_index.exs index df4ac7782..faed5e31b 100644 --- a/priv/repo/migrations/20190603162018_add_object_in_reply_to_index.exs +++ b/priv/repo/migrations/20190603162018_add_object_in_reply_to_index.exs @@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.AddObjectInReplyToIndex do use Ecto.Migration def change do - create index(:objects, ["(data->>'inReplyTo')"], name: :objects_in_reply_to_index) + create(index(:objects, ["(data->>'inReplyTo')"], name: :objects_in_reply_to_index)) end end diff --git a/priv/repo/migrations/20190603173419_add_tag_index_to_objects.exs b/priv/repo/migrations/20190603173419_add_tag_index_to_objects.exs index 93d57a249..9ba95917c 100644 --- a/priv/repo/migrations/20190603173419_add_tag_index_to_objects.exs +++ b/priv/repo/migrations/20190603173419_add_tag_index_to_objects.exs @@ -2,7 +2,10 @@ defmodule Pleroma.Repo.Migrations.AddTagIndexToObjects do use Ecto.Migration def change do - drop_if_exists index(:activities, ["(data #> '{\"object\",\"tag\"}')"], using: :gin, name: :activities_tags) - create_if_not_exists index(:objects, ["(data->'tag')"], using: :gin, name: :objects_tags) + drop_if_exists( + index(:activities, ["(data #> '{\"object\",\"tag\"}')"], using: :gin, name: :activities_tags) + ) + + create_if_not_exists(index(:objects, ["(data->'tag')"], using: :gin, name: :objects_tags)) end end 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 b717cab2e..bc4e828cc 100644 --- a/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs +++ b/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs @@ -3,6 +3,8 @@ defmodule Pleroma.Repo.Migrations.CopyMutedToMutedNotifications do alias Pleroma.User def change do - execute("update users set info = jsonb_set(info, '{muted_notifications}', info->'mutes', true) where local = true") + execute( + "update users set info = jsonb_set(info, '{muted_notifications}', info->'mutes', true) where local = true" + ) end end diff --git a/priv/repo/migrations/20190801154554_create_conversation_participation_recipient_ships.exs b/priv/repo/migrations/20190801154554_create_conversation_participation_recipient_ships.exs index c6e3469d5..59cbe25ad 100644 --- a/priv/repo/migrations/20190801154554_create_conversation_participation_recipient_ships.exs +++ b/priv/repo/migrations/20190801154554_create_conversation_participation_recipient_ships.exs @@ -7,7 +7,7 @@ defmodule Pleroma.Repo.Migrations.CreateConversationParticipationRecipientShips add(:participation_id, references(:conversation_participations, on_delete: :delete_all)) end - create_if_not_exists index(:conversation_participation_recipient_ships, [:user_id]) - create_if_not_exists index(:conversation_participation_recipient_ships, [:participation_id]) + create_if_not_exists(index(:conversation_participation_recipient_ships, [:user_id])) + create_if_not_exists(index(:conversation_participation_recipient_ships, [:participation_id])) end end diff --git a/priv/repo/migrations/20190823000549_add_likes_index_to_objects.exs b/priv/repo/migrations/20190823000549_add_likes_index_to_objects.exs index 13f3d6e83..c410dcdc2 100644 --- a/priv/repo/migrations/20190823000549_add_likes_index_to_objects.exs +++ b/priv/repo/migrations/20190823000549_add_likes_index_to_objects.exs @@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.AddLikesIndexToObjects do use Ecto.Migration def change do - create_if_not_exists index(:objects, ["(data->'likes')"], using: :gin, name: :objects_likes) + create_if_not_exists(index(:objects, ["(data->'likes')"], using: :gin, name: :objects_likes)) end end diff --git a/priv/repo/migrations/20190912065617_create_deliveries.exs b/priv/repo/migrations/20190912065617_create_deliveries.exs index 79071a799..ac2832a77 100644 --- a/priv/repo/migrations/20190912065617_create_deliveries.exs +++ b/priv/repo/migrations/20190912065617_create_deliveries.exs @@ -6,7 +6,8 @@ defmodule Pleroma.Repo.Migrations.CreateDeliveries do add(:object_id, references(:objects, type: :id), null: false) add(:user_id, references(:users, type: :uuid, on_delete: :delete_all), null: false) end - create_if_not_exists index(:deliveries, :object_id, name: :deliveries_object_id) + + create_if_not_exists(index(:deliveries, :object_id, name: :deliveries_object_id)) create_if_not_exists(unique_index(:deliveries, [:user_id, :object_id])) end end diff --git a/priv/repo/migrations/20190929201536_drop_subscription_if_exists.exs b/priv/repo/migrations/20190929201536_drop_subscription_if_exists.exs index bbf70f78b..8bd2a98bb 100644 --- a/priv/repo/migrations/20190929201536_drop_subscription_if_exists.exs +++ b/priv/repo/migrations/20190929201536_drop_subscription_if_exists.exs @@ -2,7 +2,6 @@ defmodule Pleroma.Repo.Migrations.DropSubscriptionIfExists do use Ecto.Migration def change do - end def up do @@ -10,6 +9,7 @@ defmodule Pleroma.Repo.Migrations.DropSubscriptionIfExists do drop_if_exists(index(:subscription_notifications, ["id desc nulls last"])) drop_if_exists(table(:subscription_notifications)) end + def down do :ok end diff --git a/priv/repo/migrations/20191006123824_add_keys_column.exs b/priv/repo/migrations/20191006123824_add_keys_column.exs index b6c615646..4114ba416 100644 --- a/priv/repo/migrations/20191006123824_add_keys_column.exs +++ b/priv/repo/migrations/20191006123824_add_keys_column.exs @@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.AddKeysColumn do def change do alter table("users") do - add_if_not_exists :keys, :text + 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 index 504dde53a..cb8d4ae9e 100644 --- a/priv/repo/migrations/20191006135457_move_keys_to_separate_column.exs +++ b/priv/repo/migrations/20191006135457_move_keys_to_separate_column.exs @@ -2,6 +2,9 @@ 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") + 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 From 580a67f5ca152fa4454fd9d8ab2e2a5a55af1a2a Mon Sep 17 00:00:00 2001 From: eugenijm Date: Wed, 9 Oct 2019 06:51:14 +0300 Subject: [PATCH 2/6] Mastodon API: Return `pleroma.direct_conversation_id` when viewing a status (`GET /api/v1/statuses/:id`) --- CHANGELOG.md | 1 + .../controllers/status_controller.ex | 6 +++++- .../controllers/status_controller_test.exs | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b24db7f4..da921b98e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Admin API: Return link alongside with token on password reset - MRF (Simple Policy): Also use `:accept`/`:reject` on the actors rather than only their activities - OStatus: Extract RSS functionality +- Mastodon API: Add `pleroma.direct_conversation_id` to the status endpoint (`GET /api/v1/statuses/:id`) ### Fixed - Mastodon API: Fix private and direct statuses not being filtered out from the public timeline for an authenticated user (`GET /api/v1/timelines/public`) diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index 0c16e9b0f..e5d016f63 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -167,7 +167,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do def show(%{assigns: %{user: user}} = conn, %{"id" => id}) do with %Activity{} = activity <- Activity.get_by_id_with_object(id), true <- Visibility.visible_for_user?(activity, user) do - try_render(conn, "show.json", activity: activity, for: user) + try_render(conn, "show.json", + activity: activity, + for: user, + with_direct_conversation_id: true + ) end end diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs index a4bbfe055..2de2725e0 100644 --- a/test/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/web/mastodon_api/controllers/status_controller_test.exs @@ -8,6 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do alias Pleroma.Activity alias Pleroma.ActivityExpiration alias Pleroma.Config + alias Pleroma.Conversation.Participation alias Pleroma.Object alias Pleroma.Repo alias Pleroma.ScheduledActivity @@ -465,6 +466,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do assert id == to_string(activity.id) end + test "get a direct status", %{conn: conn} do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = + CommonAPI.post(user, %{"status" => "@#{other_user.nickname}", "visibility" => "direct"}) + + conn = + conn + |> assign(:user, user) + |> get("/api/v1/statuses/#{activity.id}") + + [participation] = Participation.for_user(user) + + res = json_response(conn, 200) + assert res["pleroma"]["direct_conversation_id"] == participation.id + end + test "get statuses by IDs", %{conn: conn} do %{id: id1} = insert(:note_activity) %{id: id2} = insert(:note_activity) From d537bfd4e1e3119188519a4b1839fdbe3f6fad39 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Wed, 9 Oct 2019 13:11:57 +0700 Subject: [PATCH 3/6] Add a task to re-count statuses for all users --- CHANGELOG.md | 1 + lib/mix/tasks/pleroma/count_statuses.ex | 22 ++++++++++++++ test/tasks/count_statuses_test.exs | 39 +++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 lib/mix/tasks/pleroma/count_statuses.ex create mode 100644 test/tasks/count_statuses_test.exs diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b24db7f4..759745dd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - OAuth: support for hierarchical permissions / [Mastodon 2.4.3 OAuth permissions](https://docs.joinmastodon.org/api/permissions/) - Authentication: Added rate limit for password-authorized actions / login existence checks - Metadata Link: Atom syndication Feed +- Mix task to re-count statuses for all users (`mix pleroma.count_statuses`) ### Changed - **Breaking:** Elixir >=1.8 is now required (was >= 1.7) diff --git a/lib/mix/tasks/pleroma/count_statuses.ex b/lib/mix/tasks/pleroma/count_statuses.ex new file mode 100644 index 000000000..e1e8195dd --- /dev/null +++ b/lib/mix/tasks/pleroma/count_statuses.ex @@ -0,0 +1,22 @@ +defmodule Mix.Tasks.Pleroma.CountStatuses do + @shortdoc "Re-counts statuses for all users" + + use Mix.Task + alias Pleroma.User + import Ecto.Query + + def run([]) do + Mix.Pleroma.start_pleroma() + + stream = + User + |> where(local: true) + |> Pleroma.Repo.stream() + + Pleroma.Repo.transaction(fn -> + Enum.each(stream, &User.update_note_count/1) + end) + + Mix.Pleroma.shell_info("Done") + end +end diff --git a/test/tasks/count_statuses_test.exs b/test/tasks/count_statuses_test.exs new file mode 100644 index 000000000..6035da3c3 --- /dev/null +++ b/test/tasks/count_statuses_test.exs @@ -0,0 +1,39 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Mix.Tasks.Pleroma.CountStatusesTest do + use Pleroma.DataCase + + alias Pleroma.User + alias Pleroma.Web.CommonAPI + + import ExUnit.CaptureIO, only: [capture_io: 1] + import Pleroma.Factory + + test "counts statuses" do + user = insert(:user) + {:ok, _} = CommonAPI.post(user, %{"status" => "test"}) + {:ok, _} = CommonAPI.post(user, %{"status" => "test2"}) + + user2 = insert(:user) + {:ok, _} = CommonAPI.post(user2, %{"status" => "test3"}) + + user = refresh_record(user) + user2 = refresh_record(user2) + + assert %{info: %{note_count: 2}} = user + assert %{info: %{note_count: 1}} = user2 + + {:ok, user} = User.update_info(user, &User.Info.set_note_count(&1, 0)) + {:ok, user2} = User.update_info(user2, &User.Info.set_note_count(&1, 0)) + + assert %{info: %{note_count: 0}} = user + assert %{info: %{note_count: 0}} = user2 + + assert capture_io(fn -> Mix.Tasks.Pleroma.CountStatuses.run([]) end) == "Done\n" + + assert %{info: %{note_count: 2}} = refresh_record(user) + assert %{info: %{note_count: 1}} = refresh_record(user2) + end +end From c1bae0137666505c16482fd22cb3a14bed7a4499 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 9 Oct 2019 16:03:45 +0200 Subject: [PATCH 4/6] Search: Add tests for unicode searches. --- test/activity_test.exs | 18 +++++++++++++++++- .../controllers/search_controller_test.exs | 15 +++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/test/activity_test.exs b/test/activity_test.exs index 95d9341c4..e7ea2bd5e 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -126,9 +126,25 @@ defmodule Pleroma.ActivityTest do } {:ok, local_activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "find me!"}) + {:ok, japanese_activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "更新情報"}) {:ok, job} = Pleroma.Web.Federator.incoming_ap_doc(params) {:ok, remote_activity} = ObanHelpers.perform(job) - %{local_activity: local_activity, remote_activity: remote_activity, user: user} + + %{ + japanese_activity: japanese_activity, + local_activity: local_activity, + remote_activity: remote_activity, + user: user + } + end + + test "finds utf8 text in statuses", %{ + japanese_activity: japanese_activity, + user: user + } do + activities = Activity.search(user, "更新情報") + + assert [^japanese_activity] = activities end test "find local and remote statuses for authenticated users", %{ diff --git a/test/web/mastodon_api/controllers/search_controller_test.exs b/test/web/mastodon_api/controllers/search_controller_test.exs index 49c79ff0a..0ca896e01 100644 --- a/test/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/web/mastodon_api/controllers/search_controller_test.exs @@ -40,7 +40,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do test "search", %{conn: conn} do user = insert(:user) user_two = insert(:user, %{nickname: "shp@shitposter.club"}) - user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"}) + user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu 天子"}) {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu private"}) @@ -52,9 +52,9 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"}) - conn = get(conn, "/api/v2/search", %{"q" => "2hu #private"}) - - assert results = json_response(conn, 200) + results = + get(conn, "/api/v2/search", %{"q" => "2hu #private"}) + |> json_response(200) [account | _] = results["accounts"] assert account["id"] == to_string(user_three.id) @@ -65,6 +65,13 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do [status] = results["statuses"] assert status["id"] == to_string(activity.id) + + results = + get(conn, "/api/v2/search", %{"q" => "天子"}) + |> json_response(200) + + [account] == results["accounts"] + assert account["id"] == to_string(user_three.id) end end From dc6d20b68d3940b9537981a2556980a6ee3a43e3 Mon Sep 17 00:00:00 2001 From: Steven Fuchs Date: Wed, 9 Oct 2019 16:32:28 +0000 Subject: [PATCH 5/6] provide mocks for webfinger endpoints --- test/fixtures/tesla_mock/mstdn.jp_host_meta | 4 + .../pekorino@pawoo.net_host_meta.json | 12 ++ test/fixtures/tesla_mock/sdf.org_host_meta | 4 + .../snowdusk@sdf.org_host_meta.json | 12 ++ test/fixtures/tesla_mock/soykaf.com_host_meta | 4 + .../stopwatchingus-heidelberg.de_host_meta | 31 ++++ .../fixtures/tesla_mock/xn--q9jyb4c_host_meta | 4 + test/support/http_request_mock.ex | 175 ++++++++++++++++++ 8 files changed, 246 insertions(+) create mode 100644 test/fixtures/tesla_mock/mstdn.jp_host_meta create mode 100644 test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json create mode 100644 test/fixtures/tesla_mock/sdf.org_host_meta create mode 100644 test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json create mode 100644 test/fixtures/tesla_mock/soykaf.com_host_meta create mode 100644 test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta create mode 100644 test/fixtures/tesla_mock/xn--q9jyb4c_host_meta diff --git a/test/fixtures/tesla_mock/mstdn.jp_host_meta b/test/fixtures/tesla_mock/mstdn.jp_host_meta new file mode 100644 index 000000000..e76ddd47f --- /dev/null +++ b/test/fixtures/tesla_mock/mstdn.jp_host_meta @@ -0,0 +1,4 @@ + + + + diff --git a/test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json b/test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json new file mode 100644 index 000000000..3757c0dad --- /dev/null +++ b/test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json @@ -0,0 +1,12 @@ +{ + "subject":"acct:pekorino@pawoo.net", + "aliases":["https://pawoo.net/@pekorino","https://pawoo.net/users/pekorino"], + "links":[ + {"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"https://pawoo.net/@pekorino"}, + {"rel":"http://schemas.google.com/g/2010#updates-from","type":"application/atom+xml","href":"https://pawoo.net/users/pekorino.atom"}, + {"rel":"self","type":"application/activity+json","href":"https://pawoo.net/users/pekorino"}, + {"rel":"salmon","href":"https://pawoo.net/api/salmon/128378"}, + {"rel":"magic-public-key","href":"data:application/magic-public-key,RSA.1x8XXmBqzyb-QRkfUKxKPd7Ac2KbaFhdKy2FkJY64G-ifga-BppzEb62Q5TdkRdVKdHjh5qI7A1Hk3KfnNQcNWqqak-jxII_txC2grbWpp7v-boceD2pnzdVK5l-RR-9wEwxcoCUeRWS1Ak6DStqE5tFQOAK4IIGQB-thSQGlU75KZ-2080fPA3Xc_ycH3_eB4YqawSxXrh6IeScMevN0YHSF84GAcvhXmwLKZRugiF6nYrknbPEe_niIOmN8hhEXLN9_4kDcH83hkVZd5VXssRrxqDhtokx9emvTHkA7sY1AjYeehTPZErlV74GN-kFYLeI6DluXoSI2sX1QcS08w==.AQAB"}, + {"rel":"http://ostatus.org/schema/1.0/subscribe","template":"https://pawoo.net/authorize_follow?acct={uri}"} + ] +} diff --git a/test/fixtures/tesla_mock/sdf.org_host_meta b/test/fixtures/tesla_mock/sdf.org_host_meta new file mode 100644 index 000000000..0ffc4f096 --- /dev/null +++ b/test/fixtures/tesla_mock/sdf.org_host_meta @@ -0,0 +1,4 @@ + + + + diff --git a/test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json b/test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json new file mode 100644 index 000000000..273fc3804 --- /dev/null +++ b/test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json @@ -0,0 +1,12 @@ +{ + "subject":"acct:snowdusk@mastodon.sdf.org", + "aliases":["https://mastodon.sdf.org/@snowdusk","https://mastodon.sdf.org/users/snowdusk"], + "links":[ + {"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"https://mastodon.sdf.org/@snowdusk"}, + {"rel":"http://schemas.google.com/g/2010#updates-from","type":"application/atom+xml","href":"https://mastodon.sdf.org/users/snowdusk.atom"}, + {"rel":"self","type":"application/activity+json","href":"https://mastodon.sdf.org/users/snowdusk"}, + {"rel":"salmon","href":"https://mastodon.sdf.org/api/salmon/2"}, + {"rel":"magic-public-key","href":"data:application/magic-public-key,RSA.k4_Hr0WQUHumAD4uwWIz7OybovIKgIuanbXhX5pl7oGyb2TuifBf3nAqEhD6eLSo6-_6160L4BvPPV_l_6rlZEi6_nbeJUgVkayZgcZN3oou3IErSt8L0IbUdWT5s4fWM2zpkndLCkVbeeNQ3DOBccvJw7iA_QNTao8wr3ILvQaKEDnf-H5QBd9Tj3seyo4-7E0e6wCKOH_uBm8pSRgpdMdl2CehiFzaABBkmCeUKH-buU7iNQGi0fsV5VIHn6zffrv6p0EVNkjTDi1vTmmfrp9W0mcKZJ9DtvdehOKSgh3J7Mem-ILbPy6FSL2Oi6Ekj_Wh4M8Ie-YKuxI3N_0Baw==.AQAB"}, + {"rel":"http://ostatus.org/schema/1.0/subscribe","template":"https://mastodon.sdf.org/authorize_interaction?uri={uri}"} + ] +} diff --git a/test/fixtures/tesla_mock/soykaf.com_host_meta b/test/fixtures/tesla_mock/soykaf.com_host_meta new file mode 100644 index 000000000..99d552d32 --- /dev/null +++ b/test/fixtures/tesla_mock/soykaf.com_host_meta @@ -0,0 +1,4 @@ + + + + diff --git a/test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta b/test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta new file mode 100644 index 000000000..481cfec8d --- /dev/null +++ b/test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta @@ -0,0 +1,31 @@ +{ + "links":[ + { + "rel":"lrdd", + "type":"application\/jrd+json", + "template":"https:\/\/social.stopwatchingus-heidelberg.de\/.well-known\/webfinger?resource={uri}" + }, + { + "rel":"lrdd", + "type":"application\/json", + "template":"https:\/\/social.stopwatchingus-heidelberg.de\/.well-known\/webfinger?resource={uri}" + }, + { + "rel":"lrdd", + "type":"application\/xrd+xml", + "template":"https:\/\/social.stopwatchingus-heidelberg.de\/.well-known\/webfinger?resource={uri}" + }, + { + "rel":"http:\/\/apinamespace.org\/oauth\/access_token", + "href":"https:\/\/social.stopwatchingus-heidelberg.de\/api\/oauth\/access_token" + }, + { + "rel":"http:\/\/apinamespace.org\/oauth\/request_token", + "href":"https:\/\/social.stopwatchingus-heidelberg.de\/api\/oauth\/request_token" + }, + { + "rel":"http:\/\/apinamespace.org\/oauth\/authorize", + "href":"https:\/\/social.stopwatchingus-heidelberg.de\/api\/oauth\/authorize" + } + ] +} diff --git a/test/fixtures/tesla_mock/xn--q9jyb4c_host_meta b/test/fixtures/tesla_mock/xn--q9jyb4c_host_meta new file mode 100644 index 000000000..45d260e55 --- /dev/null +++ b/test/fixtures/tesla_mock/xn--q9jyb4c_host_meta @@ -0,0 +1,4 @@ + + + + diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index b825a9307..4feb57f3a 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -344,6 +344,181 @@ defmodule HttpRequestMock do {:error, :nxdomain} end + def get("http://osada.macgirvin.com/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 404, + body: "" + }} + end + + def get("https://osada.macgirvin.com/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 404, + body: "" + }} + end + + def get("http://mastodon.sdf.org/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta") + }} + end + + def get("https://mastodon.sdf.org/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta") + }} + end + + def get( + "https://mastodon.sdf.org/.well-known/webfinger?resource=https://mastodon.sdf.org/users/snowdusk", + _, + _, + _ + ) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json") + }} + end + + def get("http://mstdn.jp/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta") + }} + end + + def get("https://mstdn.jp/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta") + }} + end + + def get("https://mstdn.jp/.well-known/webfinger?resource=kpherox@mstdn.jp", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml") + }} + end + + def get("http://mamot.fr/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta") + }} + end + + def get("https://mamot.fr/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta") + }} + end + + def get( + "https://mamot.fr/.well-known/webfinger?resource=https://mamot.fr/users/Skruyb", + _, + _, + _ + ) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom") + }} + end + + def get("http://pawoo.net/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta") + }} + end + + def get("https://pawoo.net/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta") + }} + end + + def get( + "https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino", + _, + _, + _ + ) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json") + }} + end + + def get("http://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta") + }} + end + + def get("https://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta") + }} + end + + def get("http://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta") + }} + end + + def get("https://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta") + }} + end + + def get("http://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta") + }} + end + + def get("https://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta") + }} + end + def get( "http://mastodon.example.org/@admin/99541947525187367", _, From b750135acd9d1f8444f85ea5e0345483599daed9 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 11 Oct 2019 13:22:21 +0300 Subject: [PATCH 6/6] pleroma_ctl: Make it possible to specify branches/flavours when updating --- rel/files/bin/pleroma_ctl | 94 +++++++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 29 deletions(-) diff --git a/rel/files/bin/pleroma_ctl b/rel/files/bin/pleroma_ctl index e731d20eb..f767fe134 100755 --- a/rel/files/bin/pleroma_ctl +++ b/rel/files/bin/pleroma_ctl @@ -37,29 +37,60 @@ detect_branch() { elif [ "$branch" = "" ]; then echo "master" else - # Note: branch name in version is of SemVer format and may only contain [0-9a-zA-Z-] symbols — - # if supporting releases for more branches, need to ensure they contain only these symbols. + # Note: branch name in version is of SemVer format and may only contain [0-9a-zA-Z-] symbols — + # if supporting releases for more branches, need to ensure they contain only these symbols. echo "Releases are built only for master and develop branches" >&2 exit 1 fi } update() { set -e + NO_RM=false + + while echo "$1" | grep "^-" >/dev/null; do + case "$1" in + --zip-url) + FULL_URI="$2" + shift 2 + ;; + --no-rm) + NO_RM=true + shift + ;; + --flavour) + FLAVOUR="$2" + shift 2 + ;; + --branch) + BRANCH="$2" + shift 2 + ;; + --tmp-dir) + TMP_DIR="$2" + shift 2 + ;; + -*) + echo "invalid option: $1" 1>&2 + shift + ;; + esac + done + RELEASE_ROOT=$(dirname "$SCRIPTPATH") - uri="${PLEROMA_CTL_URI:-https://git.pleroma.social}" - project_id="${PLEROMA_CTL_PROJECT_ID:-2}" - project_branch="$(detect_branch)" - flavour="${PLEROMA_CTL_FLAVOUR:-$(detect_flavour)}" - echo "Detected flavour: $flavour" - tmp="${PLEROMA_CTL_TMP_DIR:-/tmp}" + uri="https://git.pleroma.social" + project_id="2" + project_branch="${BRANCH:-$(detect_branch)}" + flavour="${FLAVOUR:-$(detect_flavour)}" + tmp="${TMP_DIR:-/tmp}" artifact="$tmp/pleroma.zip" - full_uri="${uri}/api/v4/projects/${project_id}/jobs/artifacts/${project_branch}/download?job=${flavour}" + full_uri="${FULL_URI:-${uri}/api/v4/projects/${project_id}/jobs/artifacts/${project_branch}/download?job=${flavour}}" echo "Downloading the artifact from ${full_uri} to ${artifact}" curl "$full_uri" -o "${artifact}" echo "Unpacking ${artifact} to ${tmp}" unzip -q "$artifact" -d "$tmp" echo "Copying files over to $RELEASE_ROOT" - if [ "$1" != "--no-rm" ]; then + if [ "$NO_RM" = false ]; then + echo "Removing files from the previous release" rm -r "${RELEASE_ROOT:-?}"/* fi cp -rf "$tmp/release"/* "$RELEASE_ROOT" @@ -86,36 +117,41 @@ if [ -z "$1" ] || [ "$1" = "help" ]; then Rollback database migrations (needs to be done before downgrading) update [OPTIONS] - Update the instance using the latest CI artifact for the current branch. - - The only supported option is --no-rm, when set the script won't delete the whole directory, but - just force copy over files from the new release. This wastes more space, but may be useful if - some files are stored inside of the release directories (although you really shouldn't store them - there), or if you want to be able to quickly revert a broken update. - - The script will try to detect your architecture and ABI and set a flavour automatically, - but if it is wrong, you can overwrite it by setting PLEROMA_CTL_FLAVOUR to the desired flavour. - - By default the artifact will be downloaded from https://git.pleroma.social for pleroma/pleroma (project id: 2) - to /tmp/, you can overwrite these settings by setting PLEROMA_CTL_URI, PLEROMA_CTL_PROJECT_ID and PLEROMA_CTL_TMP_DIR - respectively. + Update the instance. + Options: + --branch Update to a specified branch, instead of the latest version of the current one. + --flavour Update to a specified flavour (CPU architecture+libc), instead of the current one. + --zip-url Get the release from a specified url. If set, renders the previous 2 options inactive. + --no-rm Do not erase previous release's files. + --tmp-dir Download the temporary files to a specified directory. and any mix tasks under Pleroma namespace, for example \`mix pleroma.user COMMAND\` is equivalent to \`$(basename "$0") user COMMAND\` By default pleroma_ctl will try calling into a running instance to execute non migration-related commands, - if for some reason this is undesired, set PLEROMA_CTL_RPC_DISABLED environment variable + if for some reason this is undesired, set PLEROMA_CTL_RPC_DISABLED environment variable. + " else SCRIPT=$(readlink -f "$0") SCRIPTPATH=$(dirname "$SCRIPT") - if [ "$1" = "update" ]; then - update "$2" - elif [ "$1" = "migrate" ] || [ "$1" = "rollback" ] || [ "$1" = "create" ] || [ "$1 $2" = "instance gen" ] || [ -n "$PLEROMA_CTL_RPC_DISABLED" ]; then - "$SCRIPTPATH"/pleroma eval 'Pleroma.ReleaseTasks.run("'"$*"'")' + FULL_ARGS="$*" + + ACTION="$1" + shift + + if [ "$(echo \"$1\" | grep \"^-\" >/dev/null)" = false ]; then + SUBACTION="$1" + shift + fi + + if [ "$ACTION" = "update" ]; then + update "$@" + elif [ "$ACTION" = "migrate" ] || [ "$ACTION" = "rollback" ] || [ "$ACTION" = "create" ] || [ "$ACTION $SUBACTION" = "instance gen" ] || [ "$PLEROMA_CTL_RPC_DISABLED" = true ]; then + "$SCRIPTPATH"/pleroma eval 'Pleroma.ReleaseTasks.run("'"$FULL_ARGS"'")' else - "$SCRIPTPATH"/pleroma rpc 'Pleroma.ReleaseTasks.run("'"$*"'")' + "$SCRIPTPATH"/pleroma rpc 'Pleroma.ReleaseTasks.run("'"$FULL_ARGS"'")' fi fi