summaryrefslogtreecommitdiff
path: root/priv/repo
diff options
context:
space:
mode:
Diffstat (limited to 'priv/repo')
-rw-r--r--priv/repo/migrations/20170320193800_create_user.exs11
-rw-r--r--priv/repo/migrations/20170321074828_create_activity.exs5
-rw-r--r--priv/repo/migrations/20170321074832_create_object.exs3
-rw-r--r--priv/repo/migrations/20170321133335_add_following_list_to_users.exs2
-rw-r--r--priv/repo/migrations/20170321143152_add_ap_id_to_users.exs2
-rw-r--r--priv/repo/migrations/20170330153447_add_index_to_objects.exs2
-rw-r--r--priv/repo/migrations/20170415141210_add_unique_index_to_email_and_nickname.exs4
-rw-r--r--priv/repo/migrations/20170416122418_add_avatar_object_to_users.exs2
-rw-r--r--priv/repo/migrations/20170418200143_create_webssub_server_subscription.exs10
-rw-r--r--priv/repo/migrations/20170423154511_add_fields_to_users.exs4
-rw-r--r--priv/repo/migrations/20170426154155_create_websub_client_subscription.exs10
-rw-r--r--priv/repo/migrations/20170427054757_add_user_and_hub.exs4
-rw-r--r--priv/repo/migrations/20170501133231_add_id_contraints_to_activities_and_objects_part_two.exs14
-rw-r--r--priv/repo/migrations/20170502083023_add_local_field_to_activities.exs4
-rw-r--r--priv/repo/migrations/20170506222027_add_unique_index_to_apid.exs2
-rw-r--r--priv/repo/migrations/20170529093232_longer_bios.exs5
-rw-r--r--priv/repo/migrations/20170620095947_remove_activities_index.exs2
-rw-r--r--priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs13
-rw-r--r--priv/repo/migrations/20170701142005_add_actor_index_to_activity.exs4
-rw-r--r--priv/repo/migrations/20170719152213_add_follower_address_to_user.exs4
-rw-r--r--priv/repo/migrations/20170906120646_add_mastodon_apps.exs12
-rw-r--r--priv/repo/migrations/20170906143140_create_o_auth_authorizations.exs10
-rw-r--r--priv/repo/migrations/20170906152508_create_o_auth_token.exs10
-rw-r--r--priv/repo/migrations/20170911123607_create_notifications.exs8
-rw-r--r--priv/repo/migrations/20170912114248_add_context_index.exs7
-rw-r--r--priv/repo/migrations/20170916090107_add_fts_index_to_activities.exs8
-rw-r--r--priv/repo/migrations/20170917120416_add_tag_index.exs8
-rw-r--r--priv/repo/migrations/20171019141706_create_password_reset_tokens.exs6
-rw-r--r--priv/repo/migrations/20171023155035_add_second_object_index_to_activty.exs14
-rw-r--r--priv/repo/migrations/20171024090137_drop_object_index.exs2
-rw-r--r--priv/repo/migrations/20171024121413_add_object_actor_index.exs7
-rw-r--r--priv/repo/migrations/20171109091239_add_actor_to_activity.exs9
-rw-r--r--priv/repo/migrations/20171109114020_fill_actor_field.exs9
-rw-r--r--priv/repo/migrations/20171109141309_add_sort_index_to_activities.exs2
-rw-r--r--priv/repo/migrations/20171130135819_add_local_index_to_user.exs2
-rw-r--r--priv/repo/migrations/20171212163643_add_recipients_to_activities.exs4
-rw-r--r--priv/repo/migrations/20171212164525_fill_recipients_in_activities.exs12
-rw-r--r--priv/repo/migrations/20180221210540_make_following_postgres_array.exs11
-rw-r--r--priv/repo/migrations/20180325172351_add_follower_address_index_to_users.exs4
-rw-r--r--priv/repo/migrations/20180327174350_drop_local_index_on_activities.exs2
-rw-r--r--priv/repo/migrations/20180327175831_actually_drop_local_index.exs4
-rw-r--r--priv/repo/migrations/20180429094642_create_lists.exs8
-rw-r--r--priv/repo/migrations/20180513104714_modify_activity_index.exs4
-rw-r--r--priv/repo/migrations/20180516144508_add_trigram_extension.exs11
-rw-r--r--priv/repo/migrations/20180516154905_create_user_trigram_index.exs4
-rw-r--r--priv/repo/migrations/20180530123448_add_list_follow_index.exs2
-rw-r--r--priv/repo/migrations/20180606173637_create_apid_host_extraction_index.exs7
-rw-r--r--priv/repo/migrations/20180612110515_create_user_invite_tokens.exs4
-rw-r--r--priv/repo/migrations/20180617221540_create_activities_in_reply_to_index.exs7
-rw-r--r--priv/repo/migrations/20180813003722_create_filters.exs21
-rw-r--r--priv/repo/migrations/20180829082446_add_recipients_to_and_cc_fields_to_activities.exs8
-rw-r--r--priv/repo/migrations/20180829182612_activities_add_to_cc_indices.exs9
-rw-r--r--priv/repo/migrations/20180829183529_remove_recipients_to_and_cc_fields_from_activities.exs8
-rw-r--r--priv/repo/migrations/20180903114437_users_add_is_moderator_index.exs4
-rw-r--r--priv/repo/migrations/20180918182427_create_push_subscriptions.exs14
-rw-r--r--priv/repo/migrations/20180919060348_users_add_last_refreshed_at.exs2
-rw-r--r--priv/repo/migrations/20181206125616_add_tags_to_users.exs4
-rw-r--r--priv/repo/migrations/20181214121049_add_bookmarks_to_users.exs2
-rw-r--r--priv/repo/migrations/20181218172826_users_and_activities_flake_id.exs87
-rw-r--r--priv/repo/migrations/20190109152453_add_visibility_function.exs4
-rw-r--r--priv/repo/migrations/20190115085500_create_user_fts_index.exs24
-rw-r--r--priv/repo/migrations/20190122153157_update_activity_visibility.exs2
-rw-r--r--priv/repo/migrations/20190123092341_users_add_is_admin_index.exs4
-rw-r--r--priv/repo/migrations/20190123125546_create_instances.exs8
-rw-r--r--priv/repo/migrations/20190124131141_update_activity_visibility_again.exs3
-rw-r--r--priv/repo/migrations/20190127151220_add_activities_likes_index.exs8
-rw-r--r--priv/repo/migrations/20190203185340_split_hide_network.exs14
-rw-r--r--priv/repo/migrations/20190205114625_create_thread_mutes.exs8
-rw-r--r--priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs2
-rw-r--r--priv/repo/migrations/20190213185503_change_apps_scopes_to_varchar_array.exs18
-rw-r--r--priv/repo/migrations/20190213185600_data_migration_populate_o_auth_scopes.exs2
-rw-r--r--priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs2
-rw-r--r--priv/repo/migrations/20190301101154_add_default_tags_to_user.exs2
-rw-r--r--priv/repo/migrations/20190303120636_update_user_note_counters.exs8
-rw-r--r--priv/repo/migrations/20190315101315_create_registrations.exs14
-rw-r--r--priv/repo/migrations/20190325185009_create_notification_id_index.exs2
-rw-r--r--priv/repo/migrations/20190405160700_add_index_on_subscribers.exs8
-rw-r--r--priv/repo/migrations/20190408123347_create_conversations.exs6
-rw-r--r--priv/repo/migrations/20190410152859_add_participation_updated_at_index.exs2
-rw-r--r--priv/repo/migrations/20190411094120_add_index_on_user_info_deactivated.exs4
-rw-r--r--priv/repo/migrations/20190412052952_add_user_info_fields.exs20
-rw-r--r--priv/repo/migrations/20190413085040_add_signin_and_last_digest_dates_to_user.exs9
-rw-r--r--priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs10
-rw-r--r--priv/repo/migrations/20190501125843_add_fts_index_to_objects.exs15
-rw-r--r--priv/repo/migrations/20190511191044_set_default_state_to_reports.exs8
-rw-r--r--priv/repo/migrations/20190513175809_change_hide_column_in_filter_table.exs4
-rw-r--r--priv/repo/migrations/20190603162018_add_object_in_reply_to_index.exs2
-rw-r--r--priv/repo/migrations/20190603173419_add_tag_index_to_objects.exs7
-rw-r--r--priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs6
-rw-r--r--priv/repo/migrations/20190711042021_create_safe_jsonb_set.exs22
-rw-r--r--priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs21
-rw-r--r--priv/repo/migrations/20190716100804_add_expirations_table.exs10
-rw-r--r--priv/repo/migrations/20190730055101_add_oban_jobs_table.exs6
-rw-r--r--priv/repo/migrations/20190801154554_create_conversation_participation_recipient_ships.exs13
-rw-r--r--priv/repo/migrations/20190818124341_create_moderation_log.exs11
-rw-r--r--priv/repo/migrations/20190823000549_add_likes_index_to_objects.exs7
-rw-r--r--priv/repo/migrations/20190912065617_create_deliveries.exs13
-rw-r--r--priv/repo/migrations/20190917100019_update_oban.exs11
-rw-r--r--priv/repo/migrations/20190929201536_drop_subscription_if_exists.exs16
-rw-r--r--priv/repo/migrations/20191005165212_add_unread_conversation_count_to_user_info.exs11
-rw-r--r--priv/repo/migrations/20191006123824_add_keys_column.exs9
-rw-r--r--priv/repo/migrations/20191006135457_move_keys_to_separate_column.exs10
-rw-r--r--priv/repo/migrations/20191007073319_create_following_relationships.exs149
-rw-r--r--priv/repo/migrations/20191008132217_migrate_following_relationships.exs89
-rw-r--r--priv/repo/migrations/20191008132427_drop_users_following.exs16
-rw-r--r--priv/repo/migrations/20191009154606_add_user_info_columns.exs53
-rw-r--r--priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs145
-rw-r--r--priv/repo/migrations/20191014181019_create_markers.exs15
-rw-r--r--priv/repo/migrations/20191017225002_drop_websub_tables.exs10
-rw-r--r--priv/repo/migrations/20191025081729_add_move_support_to_users.exs10
-rw-r--r--priv/repo/migrations/20191025143434_add_defaults_to_tables.exs68
-rw-r--r--priv/repo/migrations/20191026190317_set_not_null_for_activities.exs17
-rw-r--r--priv/repo/migrations/20191026190415_set_not_null_for_activity_expirations.exs15
-rw-r--r--priv/repo/migrations/20191026190500_set_not_null_for_apps.exs17
-rw-r--r--priv/repo/migrations/20191026190533_set_not_null_for_bookmarks.exs17
-rw-r--r--priv/repo/migrations/20191026190622_set_not_null_for_config.exs17
-rw-r--r--priv/repo/migrations/20191026190712_set_not_null_for_conversation_participation_recipient_ships.exs17
-rw-r--r--priv/repo/migrations/20191026190759_set_not_null_for_conversation_participations.exs19
-rw-r--r--priv/repo/migrations/20191026190841_set_not_null_for_filters.exs19
-rw-r--r--priv/repo/migrations/20191026191023_set_not_null_for_instances.exs15
-rw-r--r--priv/repo/migrations/20191026191100_set_not_null_for_lists.exs15
-rw-r--r--priv/repo/migrations/20191026191134_set_not_null_for_markers.exs15
-rw-r--r--priv/repo/migrations/20191026191218_set_not_null_for_moderation_log.exs15
-rw-r--r--priv/repo/migrations/20191026191249_set_not_null_for_notifications.exs17
-rw-r--r--priv/repo/migrations/20191026191328_set_not_null_for_oauth_authorizations.exs19
-rw-r--r--priv/repo/migrations/20191026191401_set_not_null_for_oauth_tokens.exs15
-rw-r--r--priv/repo/migrations/20191026191442_set_not_null_for_objects.exs15
-rw-r--r--priv/repo/migrations/20191026191524_set_not_null_for_password_reset_tokens.exs19
-rw-r--r--priv/repo/migrations/20191026191603_set_not_null_for_push_subscriptions.exs25
-rw-r--r--priv/repo/migrations/20191026191635_set_not_null_for_registrations.exs19
-rw-r--r--priv/repo/migrations/20191026191711_set_not_null_for_scheduled_activities.exs15
-rw-r--r--priv/repo/migrations/20191026191753_set_not_null_for_thread_mutes.exs17
-rw-r--r--priv/repo/migrations/20191026191826_set_not_null_for_user_invite_tokens.exs19
-rw-r--r--priv/repo/migrations/20191026191910_set_not_null_for_users.exs44
-rw-r--r--priv/repo/migrations/20191029101340_migrate_missing_follow_requests.exs35
-rw-r--r--priv/repo/migrations/20191029172832_fix_blocked_follows.exs112
-rw-r--r--priv/repo/migrations/20191104133100_set_visible_service_actors.exs22
-rw-r--r--priv/repo/migrations/20191118084425_create_user_relationships.exs17
-rw-r--r--priv/repo/migrations/20191118084500_data_migration_populate_user_relationships.exs68
-rw-r--r--priv/repo/migrations/20191123030554_add_activitypub_actor_type.exs9
-rw-r--r--priv/repo/migrations/20191123103423_remove_info_from_users.exs9
-rw-r--r--priv/repo/migrations/20191128153944_fix_missing_following_count.exs53
-rw-r--r--priv/repo/migrations/20191203043610_create_report_notes.exs13
-rw-r--r--priv/repo/migrations/20191220174645_add_scopes_to_pleroma_feo_auth_records.exs17
144 files changed, 1903 insertions, 279 deletions
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 7e44db121..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/20190412052952_add_user_info_fields.exs b/priv/repo/migrations/20190412052952_add_user_info_fields.exs
new file mode 100644
index 000000000..646c91f32
--- /dev/null
+++ b/priv/repo/migrations/20190412052952_add_user_info_fields.exs
@@ -0,0 +1,20 @@
+defmodule Pleroma.Repo.Migrations.AddEmailNotificationsToUserInfo do
+ use Ecto.Migration
+
+ def up do
+ execute("
+ UPDATE users
+ SET info = info || '{
+ \"email_notifications\": {
+ \"digest\": false
+ }
+ }'")
+ end
+
+ def down do
+ execute("
+ UPDATE users
+ SET info = info - 'email_notifications'
+ ")
+ end
+end
diff --git a/priv/repo/migrations/20190413085040_add_signin_and_last_digest_dates_to_user.exs b/priv/repo/migrations/20190413085040_add_signin_and_last_digest_dates_to_user.exs
new file mode 100644
index 000000000..4312b171f
--- /dev/null
+++ b/priv/repo/migrations/20190413085040_add_signin_and_last_digest_dates_to_user.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.AddSigninAndLastDigestDatesToUser do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ add(:last_digest_emailed_at, :naive_datetime, default: fragment("now()"))
+ end
+ end
+end
diff --git a/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs b/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs
index ce4590954..99102117f 100644
--- a/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs
+++ b/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs
@@ -8,17 +8,17 @@ defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do
def up do
query =
- from(u in User,
+ from(u in "users",
where: u.local == true,
- where: fragment("array_length(bookmarks, 1)") > 0,
- select: %{id: u.id, bookmarks: fragment("bookmarks")}
+ where: fragment("array_length(?, 1)", u.bookmarks) > 0,
+ select: %{id: u.id, bookmarks: u.bookmarks}
)
Repo.stream(query)
|> 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/20190710125158_add_following_address_from_source_data.exs b/priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs
index 779aa382e..a5170d521 100644
--- a/priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs
+++ b/priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs
@@ -5,7 +5,11 @@ defmodule Pleroma.Repo.Migrations.AddFollowingAddressFromSourceData do
def change do
query =
- User.external_users_query()
+ User.Query.build(%{
+ external: true,
+ legacy_active: true,
+ order_by: :id
+ })
|> select([u], struct(u, [:id, :ap_id, :info]))
Pleroma.Repo.stream(query)
diff --git a/priv/repo/migrations/20190711042021_create_safe_jsonb_set.exs b/priv/repo/migrations/20190711042021_create_safe_jsonb_set.exs
new file mode 100644
index 000000000..2f336a5e8
--- /dev/null
+++ b/priv/repo/migrations/20190711042021_create_safe_jsonb_set.exs
@@ -0,0 +1,22 @@
+defmodule Pleroma.Repo.Migrations.CreateSafeJsonbSet do
+ use Ecto.Migration
+ alias Pleroma.User
+
+ def change do
+ execute("""
+ create or replace function safe_jsonb_set(target jsonb, path text[], new_value jsonb, create_missing boolean default true) returns jsonb as $$
+ declare
+ result jsonb;
+ begin
+ result := jsonb_set(target, path, coalesce(new_value, 'null'::jsonb), create_missing);
+ if result is NULL then
+ raise 'jsonb_set tried to wipe the object, please report this incindent to Pleroma bug tracker. https://git.pleroma.social/pleroma/pleroma/issues/new';
+ return target;
+ else
+ return result;
+ end if;
+ end;
+ $$ language plpgsql;
+ """)
+ 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 50669902e..fc9bf70ba 100644
--- a/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs
+++ b/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs
@@ -1,24 +1,9 @@
defmodule Pleroma.Repo.Migrations.CopyMutedToMutedNotifications do
use Ecto.Migration
- alias Pleroma.User
def change do
- query =
- User.Query.build(%{
- local: true,
- active: true,
- order_by: :id
- })
-
- Pleroma.Repo.stream(query)
- |> Enum.each(fn
- %{info: %{mutes: mutes} = info} = user ->
- info_cng =
- Ecto.Changeset.cast(info, %{muted_notifications: mutes}, [:muted_notifications])
-
- Ecto.Changeset.change(user)
- |> Ecto.Changeset.put_embed(:info, info_cng)
- |> Pleroma.Repo.update()
- end)
+ execute(
+ "update users set info = safe_jsonb_set(info, '{muted_notifications}', info->'mutes', true) where local = true"
+ )
end
end
diff --git a/priv/repo/migrations/20190716100804_add_expirations_table.exs b/priv/repo/migrations/20190716100804_add_expirations_table.exs
new file mode 100644
index 000000000..fbde8f9d6
--- /dev/null
+++ b/priv/repo/migrations/20190716100804_add_expirations_table.exs
@@ -0,0 +1,10 @@
+defmodule Pleroma.Repo.Migrations.AddExpirationsTable do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:activity_expirations) do
+ add(:activity_id, references(:activities, type: :uuid, on_delete: :delete_all))
+ add(:scheduled_at, :naive_datetime, null: false)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20190730055101_add_oban_jobs_table.exs b/priv/repo/migrations/20190730055101_add_oban_jobs_table.exs
new file mode 100644
index 000000000..2f201bd05
--- /dev/null
+++ b/priv/repo/migrations/20190730055101_add_oban_jobs_table.exs
@@ -0,0 +1,6 @@
+defmodule Pleroma.Repo.Migrations.AddObanJobsTable do
+ use Ecto.Migration
+
+ defdelegate up, to: Oban.Migrations
+ defdelegate down, to: Oban.Migrations
+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
new file mode 100644
index 000000000..59cbe25ad
--- /dev/null
+++ b/priv/repo/migrations/20190801154554_create_conversation_participation_recipient_ships.exs
@@ -0,0 +1,13 @@
+defmodule Pleroma.Repo.Migrations.CreateConversationParticipationRecipientShips do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:conversation_participation_recipient_ships) do
+ add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
+ 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]))
+ end
+end
diff --git a/priv/repo/migrations/20190818124341_create_moderation_log.exs b/priv/repo/migrations/20190818124341_create_moderation_log.exs
new file mode 100644
index 000000000..cef6636f3
--- /dev/null
+++ b/priv/repo/migrations/20190818124341_create_moderation_log.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Repo.Migrations.CreateModerationLog do
+ use Ecto.Migration
+
+ def change do
+ create table(:moderation_log) do
+ add(:data, :map)
+
+ timestamps()
+ end
+ 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
new file mode 100644
index 000000000..c410dcdc2
--- /dev/null
+++ b/priv/repo/migrations/20190823000549_add_likes_index_to_objects.exs
@@ -0,0 +1,7 @@
+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))
+ end
+end
diff --git a/priv/repo/migrations/20190912065617_create_deliveries.exs b/priv/repo/migrations/20190912065617_create_deliveries.exs
new file mode 100644
index 000000000..ac2832a77
--- /dev/null
+++ b/priv/repo/migrations/20190912065617_create_deliveries.exs
@@ -0,0 +1,13 @@
+defmodule Pleroma.Repo.Migrations.CreateDeliveries do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:deliveries) 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(unique_index(:deliveries, [:user_id, :object_id]))
+ end
+end
diff --git a/priv/repo/migrations/20190917100019_update_oban.exs b/priv/repo/migrations/20190917100019_update_oban.exs
new file mode 100644
index 000000000..157dc54f9
--- /dev/null
+++ b/priv/repo/migrations/20190917100019_update_oban.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Repo.Migrations.UpdateOban do
+ use Ecto.Migration
+
+ def up do
+ Oban.Migrations.up(version: 4)
+ end
+
+ def down do
+ Oban.Migrations.down(version: 2)
+ end
+end
diff --git a/priv/repo/migrations/20190929201536_drop_subscription_if_exists.exs b/priv/repo/migrations/20190929201536_drop_subscription_if_exists.exs
new file mode 100644
index 000000000..8bd2a98bb
--- /dev/null
+++ b/priv/repo/migrations/20190929201536_drop_subscription_if_exists.exs
@@ -0,0 +1,16 @@
+defmodule Pleroma.Repo.Migrations.DropSubscriptionIfExists do
+ use Ecto.Migration
+
+ def change do
+ end
+
+ def up do
+ drop_if_exists(index(:subscription_notifications, [:user_id]))
+ drop_if_exists(index(:subscription_notifications, ["id desc nulls last"]))
+ drop_if_exists(table(:subscription_notifications))
+ end
+
+ def down do
+ :ok
+ end
+end
diff --git a/priv/repo/migrations/20191005165212_add_unread_conversation_count_to_user_info.exs b/priv/repo/migrations/20191005165212_add_unread_conversation_count_to_user_info.exs
new file mode 100644
index 000000000..2aa1a012c
--- /dev/null
+++ b/priv/repo/migrations/20191005165212_add_unread_conversation_count_to_user_info.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Repo.Migrations.AddUnreadConversationCountToUserInfo do
+ use Ecto.Migration
+
+ def up do
+ execute("""
+ update users set info = jsonb_set(info, '{unread_conversation_count}', 0::varchar::jsonb, true) where local=true
+ """)
+ 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
new file mode 100644
index 000000000..4114ba416
--- /dev/null
+++ b/priv/repo/migrations/20191006123824_add_keys_column.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.AddKeysColumn do
+ use Ecto.Migration
+
+ def change do
+ alter table("users") do
+ add_if_not_exists(:keys, :text)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20191006135457_move_keys_to_separate_column.exs b/priv/repo/migrations/20191006135457_move_keys_to_separate_column.exs
new file mode 100644
index 000000000..cb8d4ae9e
--- /dev/null
+++ b/priv/repo/migrations/20191006135457_move_keys_to_separate_column.exs
@@ -0,0 +1,10 @@
+defmodule Pleroma.Repo.Migrations.MoveKeysToSeparateColumn do
+ use Ecto.Migration
+
+ def change do
+ execute(
+ "update users set keys = info->>'keys' where local",
+ "update users set info = jsonb_set(info, '{keys}'::text[], to_jsonb(keys)) where local"
+ )
+ end
+end
diff --git a/priv/repo/migrations/20191007073319_create_following_relationships.exs b/priv/repo/migrations/20191007073319_create_following_relationships.exs
new file mode 100644
index 000000000..d49e24ee4
--- /dev/null
+++ b/priv/repo/migrations/20191007073319_create_following_relationships.exs
@@ -0,0 +1,149 @@
+defmodule Pleroma.Repo.Migrations.CreateFollowingRelationships do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:following_relationships) do
+ add(:follower_id, references(:users, type: :uuid, on_delete: :delete_all), null: false)
+ add(:following_id, references(:users, type: :uuid, on_delete: :delete_all), null: false)
+ add(:state, :string, null: false)
+
+ timestamps()
+ end
+
+ create_if_not_exists(index(:following_relationships, :follower_id))
+ create_if_not_exists(unique_index(:following_relationships, [:follower_id, :following_id]))
+
+ execute(update_thread_visibility(), restore_thread_visibility())
+ end
+
+ # The only difference between the original version: `actor_user` replaced with `actor_user_following`
+ def update_thread_visibility do
+ """
+ CREATE OR REPLACE FUNCTION thread_visibility(actor varchar, activity_id varchar) RETURNS boolean AS $$
+ DECLARE
+ public varchar := 'https://www.w3.org/ns/activitystreams#Public';
+ child objects%ROWTYPE;
+ activity activities%ROWTYPE;
+ author_fa varchar;
+ valid_recipients varchar[];
+ actor_user_following varchar[];
+ BEGIN
+ --- Fetch actor following
+ SELECT array_agg(following.follower_address) INTO actor_user_following FROM following_relationships
+ JOIN users ON users.id = following_relationships.follower_id
+ JOIN users AS following ON following.id = following_relationships.following_id
+ WHERE users.ap_id = actor;
+
+ --- Fetch our initial activity.
+ SELECT * INTO activity FROM activities WHERE activities.data->>'id' = activity_id;
+
+ LOOP
+ --- Ensure that we have an activity before continuing.
+ --- If we don't, the thread is not satisfiable.
+ IF activity IS NULL THEN
+ RETURN false;
+ END IF;
+
+ --- We only care about Create activities.
+ IF activity.data->>'type' != 'Create' THEN
+ RETURN true;
+ END IF;
+
+ --- Normalize the child object into child.
+ SELECT * INTO child FROM objects
+ INNER JOIN activities ON COALESCE(activities.data->'object'->>'id', activities.data->>'object') = objects.data->>'id'
+ WHERE COALESCE(activity.data->'object'->>'id', activity.data->>'object') = objects.data->>'id';
+
+ --- Fetch the author's AS2 following collection.
+ SELECT COALESCE(users.follower_address, '') INTO author_fa FROM users WHERE users.ap_id = activity.actor;
+
+ --- Prepare valid recipients array.
+ valid_recipients := ARRAY[actor, public];
+ IF ARRAY[author_fa] && actor_user_following THEN
+ valid_recipients := valid_recipients || author_fa;
+ END IF;
+
+ --- Check visibility.
+ IF NOT valid_recipients && activity.recipients THEN
+ --- activity not visible, break out of the loop
+ RETURN false;
+ END IF;
+
+ --- If there's a parent, load it and do this all over again.
+ IF (child.data->'inReplyTo' IS NOT NULL) AND (child.data->'inReplyTo' != 'null'::jsonb) THEN
+ SELECT * INTO activity FROM activities
+ INNER JOIN objects ON COALESCE(activities.data->'object'->>'id', activities.data->>'object') = objects.data->>'id'
+ WHERE child.data->>'inReplyTo' = objects.data->>'id';
+ ELSE
+ RETURN true;
+ END IF;
+ END LOOP;
+ END;
+ $$ LANGUAGE plpgsql IMMUTABLE;
+ """
+ end
+
+ # priv/repo/migrations/20190515222404_add_thread_visibility_function.exs
+ def restore_thread_visibility do
+ """
+ CREATE OR REPLACE FUNCTION thread_visibility(actor varchar, activity_id varchar) RETURNS boolean AS $$
+ DECLARE
+ public varchar := 'https://www.w3.org/ns/activitystreams#Public';
+ child objects%ROWTYPE;
+ activity activities%ROWTYPE;
+ actor_user users%ROWTYPE;
+ author_fa varchar;
+ valid_recipients varchar[];
+ BEGIN
+ --- Fetch our actor.
+ SELECT * INTO actor_user FROM users WHERE users.ap_id = actor;
+
+ --- Fetch our initial activity.
+ SELECT * INTO activity FROM activities WHERE activities.data->>'id' = activity_id;
+
+ LOOP
+ --- Ensure that we have an activity before continuing.
+ --- If we don't, the thread is not satisfiable.
+ IF activity IS NULL THEN
+ RETURN false;
+ END IF;
+
+ --- We only care about Create activities.
+ IF activity.data->>'type' != 'Create' THEN
+ RETURN true;
+ END IF;
+
+ --- Normalize the child object into child.
+ SELECT * INTO child FROM objects
+ INNER JOIN activities ON COALESCE(activities.data->'object'->>'id', activities.data->>'object') = objects.data->>'id'
+ WHERE COALESCE(activity.data->'object'->>'id', activity.data->>'object') = objects.data->>'id';
+
+ --- Fetch the author's AS2 following collection.
+ SELECT COALESCE(users.follower_address, '') INTO author_fa FROM users WHERE users.ap_id = activity.actor;
+
+ --- Prepare valid recipients array.
+ valid_recipients := ARRAY[actor, public];
+ IF ARRAY[author_fa] && actor_user.following THEN
+ valid_recipients := valid_recipients || author_fa;
+ END IF;
+
+ --- Check visibility.
+ IF NOT valid_recipients && activity.recipients THEN
+ --- activity not visible, break out of the loop
+ RETURN false;
+ END IF;
+
+ --- If there's a parent, load it and do this all over again.
+ IF (child.data->'inReplyTo' IS NOT NULL) AND (child.data->'inReplyTo' != 'null'::jsonb) THEN
+ SELECT * INTO activity FROM activities
+ INNER JOIN objects ON COALESCE(activities.data->'object'->>'id', activities.data->>'object') = objects.data->>'id'
+ WHERE child.data->>'inReplyTo' = objects.data->>'id';
+ ELSE
+ RETURN true;
+ END IF;
+ END LOOP;
+ END;
+ $$ LANGUAGE plpgsql IMMUTABLE;
+ """
+ end
+end
diff --git a/priv/repo/migrations/20191008132217_migrate_following_relationships.exs b/priv/repo/migrations/20191008132217_migrate_following_relationships.exs
new file mode 100644
index 000000000..9d5c2648f
--- /dev/null
+++ b/priv/repo/migrations/20191008132217_migrate_following_relationships.exs
@@ -0,0 +1,89 @@
+defmodule Pleroma.Repo.Migrations.MigrateFollowingRelationships do
+ use Ecto.Migration
+
+ def change do
+ execute(import_following_from_users(), "")
+ execute(import_following_from_activities(), restore_following_column())
+ end
+
+ defp import_following_from_users do
+ """
+ INSERT INTO following_relationships (follower_id, following_id, state, inserted_at, updated_at)
+ SELECT
+ relations.follower_id,
+ following.id,
+ 'accept',
+ now(),
+ now()
+ FROM (
+ SELECT
+ users.id AS follower_id,
+ unnest(users.following) AS following_ap_id
+ FROM
+ users
+ WHERE
+ users.following != '{}'
+ AND users.local = false OR users.local = true AND users.email IS NOT NULL -- Exclude `internal/fetch` and `relay`
+ ) AS relations
+ JOIN users AS "following" ON "following".follower_address = relations.following_ap_id
+
+ WHERE relations.follower_id != following.id
+ ON CONFLICT DO NOTHING
+ """
+ end
+
+ defp import_following_from_activities do
+ """
+ INSERT INTO
+ following_relationships (
+ follower_id,
+ following_id,
+ state,
+ inserted_at,
+ updated_at
+ )
+ SELECT
+ followers.id,
+ following.id,
+ activities.data ->> 'state',
+ (activities.data ->> 'published') :: timestamp,
+ now()
+ FROM
+ activities
+ JOIN users AS followers ON (activities.actor = followers.ap_id)
+ JOIN users AS following ON (activities.data ->> 'object' = following.ap_id)
+ WHERE
+ activities.data ->> 'type' = 'Follow'
+ AND activities.data ->> 'state' IN ('accept', 'pending', 'reject')
+ ORDER BY activities.updated_at DESC
+ ON CONFLICT DO NOTHING
+ """
+ end
+
+ defp restore_following_column do
+ """
+ UPDATE
+ users
+ SET
+ following = following_query.following_array,
+ updated_at = now()
+ FROM (
+ SELECT
+ follower.id AS follower_id,
+ CASE follower.local
+ WHEN TRUE THEN
+ array_prepend(follower.follower_address, array_agg(following.follower_address))
+ ELSE
+ array_agg(following.follower_address)
+ END AS following_array
+ FROM
+ following_relationships
+ JOIN users AS follower ON follower.id = following_relationships.follower_id
+ JOIN users AS following ON following.id = following_relationships.following_id
+ GROUP BY
+ follower.id) AS following_query
+ WHERE
+ following_query.follower_id = users.id
+ """
+ end
+end
diff --git a/priv/repo/migrations/20191008132427_drop_users_following.exs b/priv/repo/migrations/20191008132427_drop_users_following.exs
new file mode 100644
index 000000000..21c0af9f4
--- /dev/null
+++ b/priv/repo/migrations/20191008132427_drop_users_following.exs
@@ -0,0 +1,16 @@
+defmodule Pleroma.Repo.Migrations.DropUsersFollowing do
+ use Ecto.Migration
+
+ # had to disable these to be able to restore `following` index concurrently
+ # https://hexdocs.pm/ecto_sql/Ecto.Migration.html#index/3-adding-dropping-indexes-concurrently
+ @disable_ddl_transaction true
+ @disable_migration_lock true
+
+ def change do
+ drop(index(:users, [:following], concurrently: true, using: :gin))
+
+ alter table(:users) do
+ remove(:following, {:array, :string}, default: [])
+ end
+ end
+end
diff --git a/priv/repo/migrations/20191009154606_add_user_info_columns.exs b/priv/repo/migrations/20191009154606_add_user_info_columns.exs
new file mode 100644
index 000000000..22a5a377f
--- /dev/null
+++ b/priv/repo/migrations/20191009154606_add_user_info_columns.exs
@@ -0,0 +1,53 @@
+defmodule Pleroma.Repo.Migrations.AddUsersInfoColumns do
+ use Ecto.Migration
+
+ @jsonb_array_default "'[]'::jsonb"
+
+ def change do
+ alter table(:users) do
+ add_if_not_exists(:banner, :map, default: %{})
+ add_if_not_exists(:background, :map, default: %{})
+ add_if_not_exists(:source_data, :map, default: %{})
+ add_if_not_exists(:note_count, :integer, default: 0)
+ add_if_not_exists(:follower_count, :integer, default: 0)
+ add_if_not_exists(:following_count, :integer, default: nil)
+ add_if_not_exists(:locked, :boolean, default: false, null: false)
+ add_if_not_exists(:confirmation_pending, :boolean, default: false, null: false)
+ add_if_not_exists(:password_reset_pending, :boolean, default: false, null: false)
+ add_if_not_exists(:confirmation_token, :text, default: nil)
+ add_if_not_exists(:default_scope, :string, default: "public")
+ add_if_not_exists(:blocks, {:array, :text}, default: [])
+ add_if_not_exists(:domain_blocks, {:array, :text}, default: [])
+ add_if_not_exists(:mutes, {:array, :text}, default: [])
+ add_if_not_exists(:muted_reblogs, {:array, :text}, default: [])
+ add_if_not_exists(:muted_notifications, {:array, :text}, default: [])
+ add_if_not_exists(:subscribers, {:array, :text}, default: [])
+ add_if_not_exists(:deactivated, :boolean, default: false, null: false)
+ add_if_not_exists(:no_rich_text, :boolean, default: false, null: false)
+ add_if_not_exists(:ap_enabled, :boolean, default: false, null: false)
+ add_if_not_exists(:is_moderator, :boolean, default: false, null: false)
+ add_if_not_exists(:is_admin, :boolean, default: false, null: false)
+ add_if_not_exists(:show_role, :boolean, default: true, null: false)
+ add_if_not_exists(:settings, :map, default: nil)
+ add_if_not_exists(:magic_key, :text, default: nil)
+ add_if_not_exists(:uri, :text, default: nil)
+ add_if_not_exists(:hide_followers_count, :boolean, default: false, null: false)
+ add_if_not_exists(:hide_follows_count, :boolean, default: false, null: false)
+ add_if_not_exists(:hide_followers, :boolean, default: false, null: false)
+ add_if_not_exists(:hide_follows, :boolean, default: false, null: false)
+ add_if_not_exists(:hide_favorites, :boolean, default: true, null: false)
+ add_if_not_exists(:unread_conversation_count, :integer, default: 0)
+ add_if_not_exists(:pinned_activities, {:array, :text}, default: [])
+ add_if_not_exists(:email_notifications, :map, default: %{"digest" => false})
+ add_if_not_exists(:mascot, :map, default: nil)
+ add_if_not_exists(:emoji, :map, default: fragment(@jsonb_array_default))
+ add_if_not_exists(:pleroma_settings_store, :map, default: %{})
+ add_if_not_exists(:fields, :map, default: fragment(@jsonb_array_default))
+ add_if_not_exists(:raw_fields, :map, default: fragment(@jsonb_array_default))
+ add_if_not_exists(:discoverable, :boolean, default: false, null: false)
+ add_if_not_exists(:invisible, :boolean, default: false, null: false)
+ add_if_not_exists(:notification_settings, :map, default: %{})
+ add_if_not_exists(:skip_thread_containment, :boolean, default: false, null: false)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs b/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs
new file mode 100644
index 000000000..cc5ae6920
--- /dev/null
+++ b/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs
@@ -0,0 +1,145 @@
+defmodule Pleroma.Repo.Migrations.CopyUsersInfoFieldsToUsers do
+ use Ecto.Migration
+
+ @jsonb_array_default "'[]'::jsonb"
+
+ @info_fields [
+ :banner,
+ :background,
+ :source_data,
+ :note_count,
+ :follower_count,
+ :following_count,
+ :locked,
+ :confirmation_pending,
+ :password_reset_pending,
+ :confirmation_token,
+ :default_scope,
+ :blocks,
+ :domain_blocks,
+ :mutes,
+ :muted_reblogs,
+ :muted_notifications,
+ :subscribers,
+ :deactivated,
+ :no_rich_text,
+ :ap_enabled,
+ :is_moderator,
+ :is_admin,
+ :show_role,
+ :settings,
+ :magic_key,
+ :uri,
+ :hide_followers_count,
+ :hide_follows_count,
+ :hide_followers,
+ :hide_follows,
+ :hide_favorites,
+ :unread_conversation_count,
+ :pinned_activities,
+ :email_notifications,
+ :mascot,
+ :emoji,
+ :pleroma_settings_store,
+ :fields,
+ :raw_fields,
+ :discoverable,
+ :invisible,
+ :skip_thread_containment,
+ :notification_settings
+ ]
+
+ @jsonb_fields [
+ :banner,
+ :background,
+ :source_data,
+ :settings,
+ :email_notifications,
+ :mascot,
+ :pleroma_settings_store,
+ :notification_settings
+ ]
+
+ @array_jsonb_fields [:emoji, :fields, :raw_fields]
+
+ @int_fields [:note_count, :follower_count, :following_count, :unread_conversation_count]
+
+ @boolean_fields [
+ :locked,
+ :confirmation_pending,
+ :password_reset_pending,
+ :deactivated,
+ :no_rich_text,
+ :ap_enabled,
+ :is_moderator,
+ :is_admin,
+ :show_role,
+ :hide_followers_count,
+ :hide_follows_count,
+ :hide_followers,
+ :hide_follows,
+ :hide_favorites,
+ :discoverable,
+ :invisible,
+ :skip_thread_containment
+ ]
+
+ @array_text_fields [
+ :blocks,
+ :domain_blocks,
+ :mutes,
+ :muted_reblogs,
+ :muted_notifications,
+ :subscribers,
+ :pinned_activities
+ ]
+
+ def change do
+ if direction() == :up do
+ sets =
+ for f <- @info_fields do
+ set_field = "#{f} ="
+
+ # Coercion of null::jsonb to NULL
+ jsonb = "case when info->>'#{f}' IS NULL then null else info->'#{f}' end"
+
+ cond do
+ f in @jsonb_fields ->
+ "#{set_field} #{jsonb}"
+
+ f in @array_jsonb_fields ->
+ "#{set_field} coalesce(#{jsonb}, #{@jsonb_array_default})"
+
+ f in @int_fields ->
+ "#{set_field} (info->>'#{f}')::int"
+
+ f in @boolean_fields ->
+ "#{set_field} coalesce((info->>'#{f}')::boolean, false)"
+
+ f in @array_text_fields ->
+ "#{set_field} ARRAY(SELECT jsonb_array_elements_text(#{jsonb}))"
+
+ true ->
+ "#{set_field} info->>'#{f}'"
+ end
+ end
+ |> Enum.join(", ")
+
+ execute("update users set " <> sets)
+
+ for index_name <- [
+ :users_deactivated_index,
+ :users_is_moderator_index,
+ :users_is_admin_index,
+ :users_subscribers_index
+ ] do
+ drop_if_exists(index(:users, [], name: index_name))
+ end
+ end
+
+ create_if_not_exists(index(:users, [:deactivated]))
+ create_if_not_exists(index(:users, [:is_moderator]))
+ create_if_not_exists(index(:users, [:is_admin]))
+ create_if_not_exists(index(:users, [:subscribers]))
+ end
+end
diff --git a/priv/repo/migrations/20191014181019_create_markers.exs b/priv/repo/migrations/20191014181019_create_markers.exs
new file mode 100644
index 000000000..c717831ba
--- /dev/null
+++ b/priv/repo/migrations/20191014181019_create_markers.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.CreateMarkers do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:markers) do
+ add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
+ add(:timeline, :string, default: "", null: false)
+ add(:last_read_id, :string, default: "", null: false)
+ add(:lock_version, :integer, default: 0, null: false)
+ timestamps()
+ end
+
+ create_if_not_exists(unique_index(:markers, [:user_id, :timeline]))
+ end
+end
diff --git a/priv/repo/migrations/20191017225002_drop_websub_tables.exs b/priv/repo/migrations/20191017225002_drop_websub_tables.exs
new file mode 100644
index 000000000..4cf67a59c
--- /dev/null
+++ b/priv/repo/migrations/20191017225002_drop_websub_tables.exs
@@ -0,0 +1,10 @@
+defmodule Pleroma.Repo.Migrations.DropWebsubTables do
+ use Ecto.Migration
+
+ def up do
+ drop_if_exists(table(:websub_client_subscriptions))
+ drop_if_exists(table(:websub_server_subscriptions))
+ end
+
+ def down, do: :noop
+end
diff --git a/priv/repo/migrations/20191025081729_add_move_support_to_users.exs b/priv/repo/migrations/20191025081729_add_move_support_to_users.exs
new file mode 100644
index 000000000..580b9eb0f
--- /dev/null
+++ b/priv/repo/migrations/20191025081729_add_move_support_to_users.exs
@@ -0,0 +1,10 @@
+defmodule Pleroma.Repo.Migrations.AddMoveSupportToUsers do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ add(:also_known_as, {:array, :string}, default: [], null: false)
+ add(:allow_following_move, :boolean, default: true, null: false)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20191025143434_add_defaults_to_tables.exs b/priv/repo/migrations/20191025143434_add_defaults_to_tables.exs
new file mode 100644
index 000000000..a5bc82335
--- /dev/null
+++ b/priv/repo/migrations/20191025143434_add_defaults_to_tables.exs
@@ -0,0 +1,68 @@
+defmodule Pleroma.Repo.Migrations.AddDefaultsToTables do
+ use Ecto.Migration
+
+ def up do
+ execute("ALTER TABLE activities
+ ALTER COLUMN recipients SET DEFAULT ARRAY[]::character varying[]")
+
+ execute("ALTER TABLE filters
+ ALTER COLUMN whole_word SET DEFAULT true")
+
+ execute("ALTER TABLE push_subscriptions
+ ALTER COLUMN data SET DEFAULT '{}'::jsonb")
+
+ execute(~s(ALTER TABLE users
+ ALTER COLUMN tags SET DEFAULT ARRAY[]::character varying[],
+ ALTER COLUMN notification_settings SET DEFAULT
+ '{"followers": true, "follows": true, "non_follows": true, "non_followers": true}'::jsonb))
+
+ # irreversible updates
+
+ execute(
+ "UPDATE activities SET recipients = ARRAY[]::character varying[] WHERE recipients IS NULL"
+ )
+
+ execute("UPDATE filters SET whole_word = true WHERE whole_word IS NULL")
+
+ execute("UPDATE push_subscriptions SET data = '{}'::jsonb WHERE data IS NULL")
+
+ execute("UPDATE users SET source_data = '{}'::jsonb where source_data IS NULL")
+ execute("UPDATE users SET note_count = 0 where note_count IS NULL")
+ execute("UPDATE users SET background = '{}'::jsonb where background IS NULL")
+ execute("UPDATE users SET follower_count = 0 where follower_count IS NULL")
+
+ execute(
+ "UPDATE users SET unread_conversation_count = 0 where unread_conversation_count IS NULL"
+ )
+
+ execute(
+ ~s(UPDATE users SET email_notifications = '{"digest": false}'::jsonb where email_notifications IS NULL)
+ )
+
+ execute("UPDATE users SET default_scope = 'public' where default_scope IS NULL")
+
+ execute(
+ "UPDATE users SET pleroma_settings_store = '{}'::jsonb where pleroma_settings_store IS NULL"
+ )
+
+ execute("UPDATE users SET tags = ARRAY[]::character varying[] WHERE tags IS NULL")
+ execute(~s(UPDATE users SET notification_settings =
+ '{"followers": true, "follows": true, "non_follows": true, "non_followers": true}'::jsonb
+ WHERE notification_settings = '{}'::jsonb))
+ end
+
+ def down do
+ execute("ALTER TABLE activities
+ ALTER COLUMN recipients DROP DEFAULT")
+
+ execute("ALTER TABLE filters
+ ALTER COLUMN whole_word DROP DEFAULT")
+
+ execute("ALTER TABLE push_subscriptions
+ ALTER COLUMN data DROP DEFAULT")
+
+ execute("ALTER TABLE users
+ ALTER COLUMN tags DROP DEFAULT,
+ ALTER COLUMN notification_settings SET DEFAULT '{}'::jsonb")
+ end
+end
diff --git a/priv/repo/migrations/20191026190317_set_not_null_for_activities.exs b/priv/repo/migrations/20191026190317_set_not_null_for_activities.exs
new file mode 100644
index 000000000..9b66f3cff
--- /dev/null
+++ b/priv/repo/migrations/20191026190317_set_not_null_for_activities.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForActivities do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE activities
+ ALTER COLUMN data SET NOT NULL,
+ ALTER COLUMN local SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE activities
+ ALTER COLUMN data DROP NOT NULL,
+ ALTER COLUMN local DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026190415_set_not_null_for_activity_expirations.exs b/priv/repo/migrations/20191026190415_set_not_null_for_activity_expirations.exs
new file mode 100644
index 000000000..e41c69e4c
--- /dev/null
+++ b/priv/repo/migrations/20191026190415_set_not_null_for_activity_expirations.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForActivityExpirations do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE activity_expirations
+ ALTER COLUMN activity_id SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE activity_expirations
+ ALTER COLUMN activity_id DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026190500_set_not_null_for_apps.exs b/priv/repo/migrations/20191026190500_set_not_null_for_apps.exs
new file mode 100644
index 000000000..a6a44ddfe
--- /dev/null
+++ b/priv/repo/migrations/20191026190500_set_not_null_for_apps.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForApps do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE apps
+ ALTER COLUMN client_name SET NOT NULL,
+ ALTER COLUMN redirect_uris SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE apps
+ ALTER COLUMN client_name DROP NOT NULL,
+ ALTER COLUMN redirect_uris DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026190533_set_not_null_for_bookmarks.exs b/priv/repo/migrations/20191026190533_set_not_null_for_bookmarks.exs
new file mode 100644
index 000000000..5f3224003
--- /dev/null
+++ b/priv/repo/migrations/20191026190533_set_not_null_for_bookmarks.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForBookmarks do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE bookmarks
+ ALTER COLUMN user_id SET NOT NULL,
+ ALTER COLUMN activity_id SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE bookmarks
+ ALTER COLUMN user_id DROP NOT NULL,
+ ALTER COLUMN activity_id DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026190622_set_not_null_for_config.exs b/priv/repo/migrations/20191026190622_set_not_null_for_config.exs
new file mode 100644
index 000000000..204272442
--- /dev/null
+++ b/priv/repo/migrations/20191026190622_set_not_null_for_config.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForConfig do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE config
+ ALTER COLUMN key SET NOT NULL,
+ ALTER COLUMN value SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE config
+ ALTER COLUMN key DROP NOT NULL,
+ ALTER COLUMN value DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026190712_set_not_null_for_conversation_participation_recipient_ships.exs b/priv/repo/migrations/20191026190712_set_not_null_for_conversation_participation_recipient_ships.exs
new file mode 100644
index 000000000..a5ab1d3c9
--- /dev/null
+++ b/priv/repo/migrations/20191026190712_set_not_null_for_conversation_participation_recipient_ships.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForConversationParticipationRecipientShips do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE conversation_participation_recipient_ships
+ ALTER COLUMN user_id SET NOT NULL,
+ ALTER COLUMN participation_id SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE conversation_participation_recipient_ships
+ ALTER COLUMN user_id DROP NOT NULL,
+ ALTER COLUMN participation_id DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026190759_set_not_null_for_conversation_participations.exs b/priv/repo/migrations/20191026190759_set_not_null_for_conversation_participations.exs
new file mode 100644
index 000000000..cabb1f29f
--- /dev/null
+++ b/priv/repo/migrations/20191026190759_set_not_null_for_conversation_participations.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForConversationParticipations do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE conversation_participations
+ ALTER COLUMN user_id SET NOT NULL,
+ ALTER COLUMN conversation_id SET NOT NULL,
+ ALTER COLUMN read SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE conversation_participations
+ ALTER COLUMN user_id DROP NOT NULL,
+ ALTER COLUMN conversation_id DROP NOT NULL,
+ ALTER COLUMN read DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026190841_set_not_null_for_filters.exs b/priv/repo/migrations/20191026190841_set_not_null_for_filters.exs
new file mode 100644
index 000000000..52d7e687a
--- /dev/null
+++ b/priv/repo/migrations/20191026190841_set_not_null_for_filters.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForFilters do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE filters
+ ALTER COLUMN user_id SET NOT NULL,
+ ALTER COLUMN filter_id SET NOT NULL,
+ ALTER COLUMN whole_word SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE filters
+ ALTER COLUMN user_id DROP NOT NULL,
+ ALTER COLUMN filter_id DROP NOT NULL,
+ ALTER COLUMN whole_word DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191023_set_not_null_for_instances.exs b/priv/repo/migrations/20191026191023_set_not_null_for_instances.exs
new file mode 100644
index 000000000..4c2560da5
--- /dev/null
+++ b/priv/repo/migrations/20191026191023_set_not_null_for_instances.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForInstances do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE instances
+ ALTER COLUMN host SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE instances
+ ALTER COLUMN host DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191100_set_not_null_for_lists.exs b/priv/repo/migrations/20191026191100_set_not_null_for_lists.exs
new file mode 100644
index 000000000..40b8b136a
--- /dev/null
+++ b/priv/repo/migrations/20191026191100_set_not_null_for_lists.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForLists do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE lists
+ ALTER COLUMN user_id SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE lists
+ ALTER COLUMN user_id DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191134_set_not_null_for_markers.exs b/priv/repo/migrations/20191026191134_set_not_null_for_markers.exs
new file mode 100644
index 000000000..7d7b73e7b
--- /dev/null
+++ b/priv/repo/migrations/20191026191134_set_not_null_for_markers.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForMarkers do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE markers
+ ALTER COLUMN user_id SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE markers
+ ALTER COLUMN user_id DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191218_set_not_null_for_moderation_log.exs b/priv/repo/migrations/20191026191218_set_not_null_for_moderation_log.exs
new file mode 100644
index 000000000..7238ca7f5
--- /dev/null
+++ b/priv/repo/migrations/20191026191218_set_not_null_for_moderation_log.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForModerationLog do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE moderation_log
+ ALTER COLUMN data SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE moderation_log
+ ALTER COLUMN data DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191249_set_not_null_for_notifications.exs b/priv/repo/migrations/20191026191249_set_not_null_for_notifications.exs
new file mode 100644
index 000000000..7e2976bab
--- /dev/null
+++ b/priv/repo/migrations/20191026191249_set_not_null_for_notifications.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForNotifications do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE notifications
+ ALTER COLUMN user_id SET NOT NULL,
+ ALTER COLUMN seen SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE notifications
+ ALTER COLUMN user_id DROP NOT NULL,
+ ALTER COLUMN seen DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191328_set_not_null_for_oauth_authorizations.exs b/priv/repo/migrations/20191026191328_set_not_null_for_oauth_authorizations.exs
new file mode 100644
index 000000000..bc6b36e69
--- /dev/null
+++ b/priv/repo/migrations/20191026191328_set_not_null_for_oauth_authorizations.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForOauthAuthorizations do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE oauth_authorizations
+ ALTER COLUMN app_id SET NOT NULL,
+ ALTER COLUMN token SET NOT NULL,
+ ALTER COLUMN used SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE oauth_authorizations
+ ALTER COLUMN app_id DROP NOT NULL,
+ ALTER COLUMN token DROP NOT NULL,
+ ALTER COLUMN used DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191401_set_not_null_for_oauth_tokens.exs b/priv/repo/migrations/20191026191401_set_not_null_for_oauth_tokens.exs
new file mode 100644
index 000000000..fe67db8cc
--- /dev/null
+++ b/priv/repo/migrations/20191026191401_set_not_null_for_oauth_tokens.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForOauthTokens do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE oauth_tokens
+ ALTER COLUMN app_id SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE oauth_tokens
+ ALTER COLUMN app_id DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191442_set_not_null_for_objects.exs b/priv/repo/migrations/20191026191442_set_not_null_for_objects.exs
new file mode 100644
index 000000000..59e89d6da
--- /dev/null
+++ b/priv/repo/migrations/20191026191442_set_not_null_for_objects.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForObjects do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE objects
+ ALTER COLUMN data SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE objects
+ ALTER COLUMN data DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191524_set_not_null_for_password_reset_tokens.exs b/priv/repo/migrations/20191026191524_set_not_null_for_password_reset_tokens.exs
new file mode 100644
index 000000000..51efadbd3
--- /dev/null
+++ b/priv/repo/migrations/20191026191524_set_not_null_for_password_reset_tokens.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForPasswordResetTokens do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE password_reset_tokens
+ ALTER COLUMN token SET NOT NULL,
+ ALTER COLUMN user_id SET NOT NULL,
+ ALTER COLUMN used SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE password_reset_tokens
+ ALTER COLUMN token DROP NOT NULL,
+ ALTER COLUMN user_id DROP NOT NULL,
+ ALTER COLUMN used DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191603_set_not_null_for_push_subscriptions.exs b/priv/repo/migrations/20191026191603_set_not_null_for_push_subscriptions.exs
new file mode 100644
index 000000000..0f3a73067
--- /dev/null
+++ b/priv/repo/migrations/20191026191603_set_not_null_for_push_subscriptions.exs
@@ -0,0 +1,25 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForPushSubscriptions do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE push_subscriptions
+ ALTER COLUMN user_id SET NOT NULL,
+ ALTER COLUMN token_id SET NOT NULL,
+ ALTER COLUMN endpoint SET NOT NULL,
+ ALTER COLUMN key_p256dh SET NOT NULL,
+ ALTER COLUMN key_auth SET NOT NULL,
+ ALTER COLUMN data SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE push_subscriptions
+ ALTER COLUMN user_id DROP NOT NULL,
+ ALTER COLUMN token_id DROP NOT NULL,
+ ALTER COLUMN endpoint DROP NOT NULL,
+ ALTER COLUMN key_p256dh DROP NOT NULL,
+ ALTER COLUMN key_auth DROP NOT NULL,
+ ALTER COLUMN data DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191635_set_not_null_for_registrations.exs b/priv/repo/migrations/20191026191635_set_not_null_for_registrations.exs
new file mode 100644
index 000000000..ddfbf4c5e
--- /dev/null
+++ b/priv/repo/migrations/20191026191635_set_not_null_for_registrations.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForRegistrations do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE registrations
+ ALTER COLUMN provider SET NOT NULL,
+ ALTER COLUMN uid SET NOT NULL,
+ ALTER COLUMN info SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE registrations
+ ALTER COLUMN provider DROP NOT NULL,
+ ALTER COLUMN uid DROP NOT NULL,
+ ALTER COLUMN info DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191711_set_not_null_for_scheduled_activities.exs b/priv/repo/migrations/20191026191711_set_not_null_for_scheduled_activities.exs
new file mode 100644
index 000000000..f1830c8c3
--- /dev/null
+++ b/priv/repo/migrations/20191026191711_set_not_null_for_scheduled_activities.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForScheduledActivities do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE scheduled_activities
+ ALTER COLUMN user_id SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE scheduled_activities
+ ALTER COLUMN user_id DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191753_set_not_null_for_thread_mutes.exs b/priv/repo/migrations/20191026191753_set_not_null_for_thread_mutes.exs
new file mode 100644
index 000000000..daa7ce314
--- /dev/null
+++ b/priv/repo/migrations/20191026191753_set_not_null_for_thread_mutes.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForThreadMutes do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE thread_mutes
+ ALTER COLUMN user_id SET NOT NULL,
+ ALTER COLUMN context SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE thread_mutes
+ ALTER COLUMN user_id DROP NOT NULL,
+ ALTER COLUMN context DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191826_set_not_null_for_user_invite_tokens.exs b/priv/repo/migrations/20191026191826_set_not_null_for_user_invite_tokens.exs
new file mode 100644
index 000000000..836544f7f
--- /dev/null
+++ b/priv/repo/migrations/20191026191826_set_not_null_for_user_invite_tokens.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForUserInviteTokens do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ execute("ALTER TABLE user_invite_tokens
+ ALTER COLUMN used SET NOT NULL,
+ ALTER COLUMN uses SET NOT NULL,
+ ALTER COLUMN invite_type SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE user_invite_tokens
+ ALTER COLUMN used DROP NOT NULL,
+ ALTER COLUMN uses DROP NOT NULL,
+ ALTER COLUMN invite_type DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191026191910_set_not_null_for_users.exs b/priv/repo/migrations/20191026191910_set_not_null_for_users.exs
new file mode 100644
index 000000000..9d8d0ccf8
--- /dev/null
+++ b/priv/repo/migrations/20191026191910_set_not_null_for_users.exs
@@ -0,0 +1,44 @@
+defmodule Pleroma.Repo.Migrations.SetNotNullForUsers do
+ use Ecto.Migration
+
+ # modify/3 function will require index recreation, so using execute/1 instead
+
+ def up do
+ # irreversible
+ execute("UPDATE users SET follower_count = 0 WHERE follower_count IS NULL")
+
+ execute("ALTER TABLE users
+ ALTER COLUMN local SET NOT NULL,
+ ALTER COLUMN source_data SET NOT NULL,
+ ALTER COLUMN note_count SET NOT NULL,
+ ALTER COLUMN follower_count SET NOT NULL,
+ ALTER COLUMN blocks SET NOT NULL,
+ ALTER COLUMN domain_blocks SET NOT NULL,
+ ALTER COLUMN mutes SET NOT NULL,
+ ALTER COLUMN muted_reblogs SET NOT NULL,
+ ALTER COLUMN muted_notifications SET NOT NULL,
+ ALTER COLUMN subscribers SET NOT NULL,
+ ALTER COLUMN pinned_activities SET NOT NULL,
+ ALTER COLUMN emoji SET NOT NULL,
+ ALTER COLUMN fields SET NOT NULL,
+ ALTER COLUMN raw_fields SET NOT NULL")
+ end
+
+ def down do
+ execute("ALTER TABLE users
+ ALTER COLUMN local DROP NOT NULL,
+ ALTER COLUMN source_data DROP NOT NULL,
+ ALTER COLUMN note_count DROP NOT NULL,
+ ALTER COLUMN follower_count DROP NOT NULL,
+ ALTER COLUMN blocks DROP NOT NULL,
+ ALTER COLUMN domain_blocks DROP NOT NULL,
+ ALTER COLUMN mutes DROP NOT NULL,
+ ALTER COLUMN muted_reblogs DROP NOT NULL,
+ ALTER COLUMN muted_notifications DROP NOT NULL,
+ ALTER COLUMN subscribers DROP NOT NULL,
+ ALTER COLUMN pinned_activities DROP NOT NULL,
+ ALTER COLUMN emoji DROP NOT NULL,
+ ALTER COLUMN fields DROP NOT NULL,
+ ALTER COLUMN raw_fields DROP NOT NULL")
+ end
+end
diff --git a/priv/repo/migrations/20191029101340_migrate_missing_follow_requests.exs b/priv/repo/migrations/20191029101340_migrate_missing_follow_requests.exs
new file mode 100644
index 000000000..90b18efc8
--- /dev/null
+++ b/priv/repo/migrations/20191029101340_migrate_missing_follow_requests.exs
@@ -0,0 +1,35 @@
+defmodule Pleroma.Repo.Migrations.MigrateMissingFollowingRelationships do
+ use Ecto.Migration
+
+ def change do
+ execute(import_pending_follows_from_activities(), "")
+ end
+
+ defp import_pending_follows_from_activities do
+ """
+ INSERT INTO
+ following_relationships (
+ follower_id,
+ following_id,
+ state,
+ inserted_at,
+ updated_at
+ )
+ SELECT
+ followers.id,
+ following.id,
+ activities.data ->> 'state',
+ (activities.data ->> 'published') :: timestamp,
+ now()
+ FROM
+ activities
+ JOIN users AS followers ON (activities.actor = followers.ap_id)
+ JOIN users AS following ON (activities.data ->> 'object' = following.ap_id)
+ WHERE
+ activities.data ->> 'type' = 'Follow'
+ AND activities.data ->> 'state' = 'pending'
+ ORDER BY activities.updated_at DESC
+ ON CONFLICT DO NOTHING
+ """
+ end
+end
diff --git a/priv/repo/migrations/20191029172832_fix_blocked_follows.exs b/priv/repo/migrations/20191029172832_fix_blocked_follows.exs
new file mode 100644
index 000000000..71f8f1330
--- /dev/null
+++ b/priv/repo/migrations/20191029172832_fix_blocked_follows.exs
@@ -0,0 +1,112 @@
+defmodule Pleroma.Repo.Migrations.FixBlockedFollows do
+ use Ecto.Migration
+
+ import Ecto.Query
+ alias Pleroma.Config
+ alias Pleroma.Repo
+
+ def up do
+ unfollow_blocked = Config.get([:activitypub, :unfollow_blocked])
+
+ if unfollow_blocked do
+ "activities"
+ |> where([activity], fragment("? ->> 'type' = 'Block'", activity.data))
+ |> distinct([activity], [
+ activity.actor,
+ fragment(
+ "coalesce((?)->'object'->>'id', (?)->>'object')",
+ activity.data,
+ activity.data
+ )
+ ])
+ |> order_by([activity], [fragment("? desc nulls last", activity.id)])
+ |> select([activity], %{
+ blocker: activity.actor,
+ blocked:
+ fragment("coalesce((?)->'object'->>'id', (?)->>'object')", activity.data, activity.data),
+ created_at: activity.id
+ })
+ |> Repo.stream()
+ |> Enum.map(&unfollow_if_blocked/1)
+ |> Enum.uniq()
+ |> Enum.each(&update_follower_count/1)
+ end
+ end
+
+ def down do
+ end
+
+ def unfollow_if_blocked(%{blocker: blocker_id, blocked: blocked_id, created_at: blocked_at}) do
+ query =
+ from(
+ activity in "activities",
+ where: fragment("? ->> 'type' = 'Follow'", activity.data),
+ where: activity.actor == ^blocked_id,
+ # this is to use the index
+ where:
+ fragment(
+ "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
+ activity.data,
+ activity.data,
+ ^blocker_id
+ ),
+ where: activity.id > ^blocked_at,
+ where: fragment("(?)->>'state' = 'accept'", activity.data),
+ order_by: [fragment("? desc nulls last", activity.id)]
+ )
+
+ unless Repo.exists?(query) do
+ blocker = "users" |> select([:id, :local]) |> Repo.get_by(ap_id: blocker_id)
+ blocked = "users" |> select([:id]) |> Repo.get_by(ap_id: blocked_id)
+
+ if !is_nil(blocker) && !is_nil(blocked) do
+ unfollow(blocked, blocker)
+ end
+ end
+ end
+
+ def unfollow(%{id: follower_id}, %{id: followed_id} = followed) do
+ following_relationship =
+ "following_relationships"
+ |> where(follower_id: ^follower_id, following_id: ^followed_id, state: "accept")
+ |> select([:id])
+ |> Repo.one()
+
+ case following_relationship do
+ nil ->
+ {:ok, nil}
+
+ %{id: following_relationship_id} ->
+ "following_relationships"
+ |> where(id: ^following_relationship_id)
+ |> Repo.delete_all()
+
+ followed
+ end
+ end
+
+ def update_follower_count(%{id: user_id} = user) do
+ if user.local or !Pleroma.Config.get([:instance, :external_user_synchronization]) do
+ follower_count_query =
+ "users"
+ |> where([u], u.id != ^user_id)
+ |> where([u], u.deactivated != ^true)
+ |> join(:inner, [u], r in "following_relationships",
+ as: :relationships,
+ on: r.following_id == ^user_id and r.follower_id == u.id
+ )
+ |> where([relationships: r], r.state == "accept")
+ |> select([u], %{count: count(u.id)})
+
+ "users"
+ |> where(id: ^user_id)
+ |> join(:inner, [u], s in subquery(follower_count_query))
+ |> update([u, s],
+ set: [follower_count: s.count]
+ )
+ |> Repo.update_all([])
+ end
+ end
+
+ def update_follower_count(_), do: :noop
+end
diff --git a/priv/repo/migrations/20191104133100_set_visible_service_actors.exs b/priv/repo/migrations/20191104133100_set_visible_service_actors.exs
new file mode 100644
index 000000000..62907093c
--- /dev/null
+++ b/priv/repo/migrations/20191104133100_set_visible_service_actors.exs
@@ -0,0 +1,22 @@
+defmodule Pleroma.Repo.Migrations.SetVisibleServiceActors do
+ use Ecto.Migration
+ import Ecto.Query
+ alias Pleroma.Repo
+
+ def up do
+ user_nicknames = ["relay", "internal.fetch"]
+
+ from(
+ u in "users",
+ where: u.nickname in ^user_nicknames,
+ update: [
+ set: [invisible: true]
+ ]
+ )
+ |> Repo.update_all([])
+ end
+
+ def down do
+ :ok
+ end
+end
diff --git a/priv/repo/migrations/20191118084425_create_user_relationships.exs b/priv/repo/migrations/20191118084425_create_user_relationships.exs
new file mode 100644
index 000000000..c281f887d
--- /dev/null
+++ b/priv/repo/migrations/20191118084425_create_user_relationships.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.CreateUserRelationships do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:user_relationships) do
+ add(:source_id, references(:users, type: :uuid, on_delete: :delete_all))
+ add(:target_id, references(:users, type: :uuid, on_delete: :delete_all))
+ add(:relationship_type, :integer, null: false)
+
+ timestamps(updated_at: false)
+ end
+
+ create_if_not_exists(
+ unique_index(:user_relationships, [:source_id, :relationship_type, :target_id])
+ )
+ end
+end
diff --git a/priv/repo/migrations/20191118084500_data_migration_populate_user_relationships.exs b/priv/repo/migrations/20191118084500_data_migration_populate_user_relationships.exs
new file mode 100644
index 000000000..990e9f3b8
--- /dev/null
+++ b/priv/repo/migrations/20191118084500_data_migration_populate_user_relationships.exs
@@ -0,0 +1,68 @@
+defmodule Pleroma.Repo.Migrations.DataMigrationPopulateUserRelationships do
+ use Ecto.Migration
+
+ alias Ecto.Adapters.SQL
+ alias Pleroma.Repo
+
+ require Logger
+
+ def up do
+ Enum.each(
+ [blocks: 1, mutes: 2, muted_reblogs: 3, muted_notifications: 4, subscribers: 5],
+ fn {field, relationship_type_code} ->
+ migrate(field, relationship_type_code)
+
+ if field == :subscribers do
+ drop_if_exists(index(:users, [:subscribers]))
+ end
+ end
+ )
+ end
+
+ def down, do: :noop
+
+ defp migrate(field, relationship_type_code) do
+ Logger.info("Processing users.#{field}...")
+
+ {:ok, %{rows: field_rows}} =
+ SQL.query(Repo, "SELECT id, #{field} FROM users WHERE #{field} != '{}'")
+
+ target_ap_ids =
+ Enum.flat_map(
+ field_rows,
+ fn [_, ap_ids] -> ap_ids end
+ )
+ |> Enum.uniq()
+
+ # Selecting ids of all targets at once in order to reduce the number of SELECT queries
+ {:ok, %{rows: target_ap_id_id}} =
+ SQL.query(Repo, "SELECT ap_id, id FROM users WHERE ap_id = ANY($1)", [target_ap_ids])
+
+ target_id_by_ap_id = Enum.into(target_ap_id_id, %{}, fn [k, v] -> {k, v} end)
+
+ Enum.each(
+ field_rows,
+ fn [source_id, target_ap_ids] ->
+ source_uuid = Ecto.UUID.cast!(source_id)
+
+ for target_ap_id <- target_ap_ids do
+ target_id = target_id_by_ap_id[target_ap_id]
+
+ with {:ok, target_uuid} <- target_id && Ecto.UUID.cast(target_id) do
+ execute("""
+ INSERT INTO user_relationships(
+ source_id, target_id, relationship_type, inserted_at
+ )
+ VALUES(
+ '#{source_uuid}'::uuid, '#{target_uuid}'::uuid, #{relationship_type_code}, now()
+ )
+ ON CONFLICT (source_id, relationship_type, target_id) DO NOTHING
+ """)
+ else
+ _ -> Logger.warn("Unresolved #{field} reference: (#{source_uuid}, #{target_id})")
+ end
+ end
+ end
+ )
+ end
+end
diff --git a/priv/repo/migrations/20191123030554_add_activitypub_actor_type.exs b/priv/repo/migrations/20191123030554_add_activitypub_actor_type.exs
new file mode 100644
index 000000000..76d3b32c4
--- /dev/null
+++ b/priv/repo/migrations/20191123030554_add_activitypub_actor_type.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.AddActivitypubActorType do
+ use Ecto.Migration
+
+ def change do
+ alter table("users") do
+ add(:actor_type, :string, null: false, default: "Person")
+ end
+ end
+end
diff --git a/priv/repo/migrations/20191123103423_remove_info_from_users.exs b/priv/repo/migrations/20191123103423_remove_info_from_users.exs
new file mode 100644
index 000000000..b251255ea
--- /dev/null
+++ b/priv/repo/migrations/20191123103423_remove_info_from_users.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.RemoveInfoFromUsers do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ remove(:info, :map, default: %{})
+ end
+ end
+end
diff --git a/priv/repo/migrations/20191128153944_fix_missing_following_count.exs b/priv/repo/migrations/20191128153944_fix_missing_following_count.exs
new file mode 100644
index 000000000..3236de7a4
--- /dev/null
+++ b/priv/repo/migrations/20191128153944_fix_missing_following_count.exs
@@ -0,0 +1,53 @@
+defmodule Pleroma.Repo.Migrations.FixMissingFollowingCount do
+ use Ecto.Migration
+
+ def up do
+ """
+ UPDATE
+ users
+ SET
+ following_count = sub.count
+ FROM
+ (
+ SELECT
+ users.id AS sub_id
+ ,COUNT (following_relationships.id)
+ FROM
+ following_relationships
+ ,users
+ WHERE
+ users.id = following_relationships.follower_id
+ AND following_relationships.state = 'accept'
+ GROUP BY
+ users.id
+ ) AS sub
+ WHERE
+ users.id = sub.sub_id
+ AND users.local = TRUE
+ ;
+ """
+ |> execute()
+
+ """
+ UPDATE
+ users
+ SET
+ following_count = 0
+ WHERE
+ following_count IS NULL
+ """
+ |> execute()
+
+ execute("ALTER TABLE users
+ ALTER COLUMN following_count SET DEFAULT 0,
+ ALTER COLUMN following_count SET NOT NULL
+ ")
+ end
+
+ def down do
+ execute("ALTER TABLE users
+ ALTER COLUMN following_count DROP DEFAULT,
+ ALTER COLUMN following_count DROP NOT NULL
+ ")
+ end
+end
diff --git a/priv/repo/migrations/20191203043610_create_report_notes.exs b/priv/repo/migrations/20191203043610_create_report_notes.exs
new file mode 100644
index 000000000..a4f8c096d
--- /dev/null
+++ b/priv/repo/migrations/20191203043610_create_report_notes.exs
@@ -0,0 +1,13 @@
+defmodule Pleroma.Repo.Migrations.CreateReportNotes do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:report_notes) do
+ add(:user_id, references(:users, type: :uuid))
+ add(:activity_id, references(:activities, type: :uuid))
+ add(:content, :string)
+
+ timestamps()
+ end
+ end
+end
diff --git a/priv/repo/migrations/20191220174645_add_scopes_to_pleroma_feo_auth_records.exs b/priv/repo/migrations/20191220174645_add_scopes_to_pleroma_feo_auth_records.exs
new file mode 100644
index 000000000..6b160ad16
--- /dev/null
+++ b/priv/repo/migrations/20191220174645_add_scopes_to_pleroma_feo_auth_records.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.AddScopesToPleromaFEOAuthRecords do
+ use Ecto.Migration
+
+ def up do
+ update_scopes_clause = "SET scopes = '{read,write,follow,push,admin}'"
+ apps_where = "WHERE apps.client_name like 'PleromaFE_%' or apps.client_name like 'AdminFE_%'"
+ app_id_subquery_where = "WHERE app_id IN (SELECT apps.id FROM apps #{apps_where})"
+
+ execute("UPDATE apps #{update_scopes_clause} #{apps_where}")
+
+ for table <- ["oauth_authorizations", "oauth_tokens"] do
+ execute("UPDATE #{table} #{update_scopes_clause} #{app_id_subquery_where}")
+ end
+ end
+
+ def down, do: :noop
+end