Merge remote-tracking branch 'parent/main' into upstream-20240424

This commit is contained in:
KMY 2024-04-24 08:57:07 +09:00
commit 32a8f367a3
91 changed files with 1073 additions and 446 deletions

View file

@ -0,0 +1,49 @@
# frozen_string_literal: true
class AddIndexToWebauthnCredentialsUserIdNickname < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
add_index_to_table
rescue ActiveRecord::RecordNotUnique
remove_duplicates_and_reindex
end
def down
remove_index_from_table
end
private
def remove_duplicates_and_reindex
deduplicate_records
reindex_records
rescue ActiveRecord::RecordNotUnique
retry
end
def reindex_records
remove_index_from_table
add_index_to_table
end
def add_index_to_table
add_index :webauthn_credentials, [:user_id, :nickname], unique: true, algorithm: :concurrently
end
def remove_index_from_table
remove_index :webauthn_credentials, [:user_id, :nickname]
end
def deduplicate_records
safety_assured do
execute <<~SQL.squish
DELETE FROM webauthn_credentials
WHERE id NOT IN (
SELECT DISTINCT ON(user_id, nickname) id FROM webauthn_credentials
ORDER BY user_id, nickname, id ASC
)
SQL
end
end
end

View file

@ -0,0 +1,49 @@
# frozen_string_literal: true
class AddIndexToAccountAliasUriAccountId < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
add_index_to_table
rescue ActiveRecord::RecordNotUnique
remove_duplicates_and_reindex
end
def down
remove_index_from_table
end
private
def remove_duplicates_and_reindex
deduplicate_records
reindex_records
rescue ActiveRecord::RecordNotUnique
retry
end
def reindex_records
remove_index_from_table
add_index_to_table
end
def add_index_to_table
add_index :account_aliases, [:account_id, :uri], unique: true, algorithm: :concurrently
end
def remove_index_from_table
remove_index :account_aliases, [:account_id, :uri]
end
def deduplicate_records
safety_assured do
execute <<~SQL.squish
DELETE FROM account_aliases
WHERE id NOT IN (
SELECT DISTINCT ON(account_id, uri) id FROM account_aliases
ORDER BY account_id, uri, id ASC
)
SQL
end
end
end

View file

@ -0,0 +1,49 @@
# frozen_string_literal: true
class AddIndexToCustomFilterStatusesStatusCustomFilter < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
add_index_to_table
rescue ActiveRecord::RecordNotUnique
remove_duplicates_and_reindex
end
def down
remove_index_from_table
end
private
def remove_duplicates_and_reindex
deduplicate_records
reindex_records
rescue ActiveRecord::RecordNotUnique
retry
end
def reindex_records
remove_index_from_table
add_index_to_table
end
def add_index_to_table
add_index :custom_filter_statuses, [:status_id, :custom_filter_id], unique: true, algorithm: :concurrently
end
def remove_index_from_table
remove_index :custom_filter_statuses, [:status_id, :custom_filter_id]
end
def deduplicate_records
safety_assured do
execute <<~SQL.squish
DELETE FROM custom_filter_statuses
WHERE id NOT IN (
SELECT DISTINCT ON(status_id, custom_filter_id) id FROM custom_filter_statuses
ORDER BY status_id, custom_filter_id, id ASC
)
SQL
end
end
end

View file

@ -0,0 +1,49 @@
# frozen_string_literal: true
class AddIndexToIdentitiesUidProvider < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
add_index_to_table
rescue ActiveRecord::RecordNotUnique
remove_duplicates_and_reindex
end
def down
remove_index_from_table
end
private
def remove_duplicates_and_reindex
deduplicate_records
reindex_records
rescue ActiveRecord::RecordNotUnique
retry
end
def reindex_records
remove_index_from_table
add_index_to_table
end
def add_index_to_table
add_index :identities, [:uid, :provider], unique: true, algorithm: :concurrently
end
def remove_index_from_table
remove_index :identities, [:uid, :provider]
end
def deduplicate_records
safety_assured do
execute <<~SQL.squish
DELETE FROM identities
WHERE id NOT IN (
SELECT DISTINCT ON(uid, provider) id FROM identities
ORDER BY uid, provider, id ASC
)
SQL
end
end
end

View file

@ -20,6 +20,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_04_01_222541) do
t.string "uri", default: "", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["account_id", "uri"], name: "index_account_aliases_on_account_id_and_uri", unique: true
t.index ["account_id"], name: "index_account_aliases_on_account_id"
end
@ -523,6 +524,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_04_01_222541) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["custom_filter_id"], name: "index_custom_filter_statuses_on_custom_filter_id"
t.index ["status_id", "custom_filter_id"], name: "index_custom_filter_statuses_on_status_id_and_custom_filter_id", unique: true
t.index ["status_id"], name: "index_custom_filter_statuses_on_status_id"
end
@ -719,6 +721,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_04_01_222541) do
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.bigint "user_id"
t.index ["uid", "provider"], name: "index_identities_on_uid_and_provider", unique: true
t.index ["user_id"], name: "index_identities_on_user_id"
end
@ -1595,6 +1598,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_04_01_222541) do
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["external_id"], name: "index_webauthn_credentials_on_external_id", unique: true
t.index ["user_id", "nickname"], name: "index_webauthn_credentials_on_user_id_and_nickname", unique: true
t.index ["user_id"], name: "index_webauthn_credentials_on_user_id"
end