Reapply "Add 'IF NOT EXISTS' to all 'CREATE INDEX CONCURRENTLY' statements to avoid deadlocks (#5297)" (#5299)

This reverts commit 2c3054bb24, reversing
changes made to 396950806c.
This commit is contained in:
Olivier 'reivilibre
2025-12-01 12:45:19 +00:00
parent 2c3054bb24
commit 1dd51c77f4
48 changed files with 49 additions and 49 deletions

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
compat_access_tokens_session_fk
ON compat_access_tokens (compat_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
compat_refresh_tokens_session_fk
ON compat_refresh_tokens (compat_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
compat_refresh_tokens_access_token_fk
ON compat_refresh_tokens (compat_access_token_id);

View File

@@ -7,7 +7,7 @@
-- Including the `last_active_at` column lets us effeciently filter in-memory
-- for those sessions without fetching the rows, and without including it in the
-- index btree
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
compat_sessions_user_fk
ON compat_sessions (user_id)
INCLUDE (last_active_at);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
compat_sessions_user_session_fk
ON compat_sessions (user_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
compat_sso_logins_session_fk
ON compat_sso_logins (compat_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_access_tokens_session_fk
ON oauth2_access_tokens (oauth2_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_authorization_grants_session_fk
ON oauth2_authorization_grants (oauth2_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_authorization_grants_client_fk
ON oauth2_authorization_grants (oauth2_client_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_consents_client_fk
ON oauth2_consents (oauth2_client_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_consents_user_fk
ON oauth2_consents (user_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_device_code_grants_client_fk
ON oauth2_device_code_grant (oauth2_client_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_device_code_grants_session_fk
ON oauth2_device_code_grant (oauth2_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_device_code_grants_user_session_fk
ON oauth2_device_code_grant (user_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_refresh_tokens_session_fk
ON oauth2_refresh_tokens (oauth2_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_refresh_tokens_access_token_fk
ON oauth2_refresh_tokens (oauth2_access_token_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_refresh_tokens_next_refresh_token_fk
ON oauth2_refresh_tokens (next_oauth2_refresh_token_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_sessions_user_session_fk
ON oauth2_sessions (user_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_sessions_client_fk
ON oauth2_sessions (oauth2_client_id);

View File

@@ -7,7 +7,7 @@
-- Including the `last_active_at` column lets us effeciently filter in-memory
-- for those sessions without fetching the rows, and without including it in the
-- index btree
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
oauth2_sessions_user_fk
ON oauth2_sessions (user_id)
INCLUDE (last_active_at);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
queue_jobs_started_by_fk
ON queue_jobs (started_by);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
queue_jobs_next_attempt_fk
ON queue_jobs (next_attempt_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
queue_jobs_schedule_name_fk
ON queue_jobs (schedule_name);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
upstream_oauth_authorization_sessions_provider_fk
ON upstream_oauth_authorization_sessions (upstream_oauth_provider_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
upstream_oauth_authorization_sessions_link_fk
ON upstream_oauth_authorization_sessions (upstream_oauth_link_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
upstream_oauth_links_provider_fk
ON upstream_oauth_links (upstream_oauth_provider_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
upstream_oauth_links_user_fk
ON upstream_oauth_links (user_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_email_authentication_codes_authentication_fk
ON user_email_authentication_codes (user_email_authentication_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_email_authentications_user_session_fk
ON user_email_authentications (user_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_email_authentications_user_registration_fk
ON user_email_authentications (user_registration_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_emails_user_fk
ON user_emails (user_id);

View File

@@ -5,6 +5,6 @@
-- Please see LICENSE in the repository root for full details.
-- This isn't a foreign key, but we really need that to be indexed
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_emails_email_idx
ON user_emails (email);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_passwords_user_fk
ON user_passwords (user_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_recovery_tickets_session_fk
ON user_recovery_tickets (user_recovery_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_recovery_tickets_user_email_fk
ON user_recovery_tickets (user_email_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_registrations_email_authentication_fk
ON user_registrations (email_authentication_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_session_authentications_user_session_fk
ON user_session_authentications (user_session_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_session_authentications_user_password_fk
ON user_session_authentications (user_password_id);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_session_authentications_upstream_oauth_session_fk
ON user_session_authentications (upstream_oauth_authorization_session_id);

View File

@@ -7,7 +7,7 @@
-- Including the `last_active_at` column lets us effeciently filter in-memory
-- for those sessions without fetching the rows, and without including it in the
-- index btree
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_sessions_user_fk
ON user_sessions (user_id)
INCLUDE (last_active_at);

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_terms_user_fk
ON user_terms (user_id);

View File

@@ -6,6 +6,6 @@
-- We don't use this column anymore, but… it will still tank the performance on
-- deletions of user_emails if we don't have it
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
users_primary_email_fk
ON users (primary_user_email_id);

View File

@@ -5,6 +5,6 @@
-- Please see LICENSE in the repository root for full details.
-- This isn't a foreign key, but we really need that to be indexed
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_recovery_tickets_ticket_idx
ON user_recovery_tickets (ticket);

View File

@@ -6,5 +6,5 @@
-- Create an index on the username column, lower-cased, so that we can lookup
-- usernames in a case-insensitive manner.
CREATE INDEX CONCURRENTLY users_lower_username_idx
CREATE INDEX CONCURRENTLY IF NOT EXISTS users_lower_username_idx
ON users (LOWER(username));

View File

@@ -4,6 +4,6 @@
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_registrations_user_registration_token_id_fk
ON user_registrations (user_registration_token_id);
ON user_registrations (user_registration_token_id);

View File

@@ -6,6 +6,6 @@
-- When we're looking up an email address, we want to be able to do a case-insensitive
-- lookup, so we index the email address lowercase and request it like that
CREATE INDEX CONCURRENTLY
CREATE INDEX CONCURRENTLY IF NOT EXISTS
user_emails_lower_email_idx
ON user_emails (LOWER(email));

View File

@@ -6,5 +6,5 @@
-- This adds an index on the username field for ILIKE '%search%' operations,
-- enabling fuzzy searches of usernames
CREATE INDEX CONCURRENTLY users_username_trgm_idx
CREATE INDEX CONCURRENTLY IF NOT EXISTS users_username_trgm_idx
ON users USING gin(username gin_trgm_ops);

View File

@@ -5,5 +5,5 @@
-- Please see LICENSE in the repository root for full details.
-- Index on the new foreign key added by the previous migration
CREATE INDEX CONCURRENTLY user_registrations_upstream_oauth_session_id_idx
CREATE INDEX CONCURRENTLY IF NOT EXISTS user_registrations_upstream_oauth_session_id_idx
ON user_registrations (upstream_oauth_authorization_session_id);