fix(webhooks): build events indexes concurrently and allow profile update#12463
Open
apoorvdixit88 wants to merge 7 commits into
Open
fix(webhooks): build events indexes concurrently and allow profile update#12463apoorvdixit88 wants to merge 7 commits into
apoorvdixit88 wants to merge 7 commits into
Conversation
…y and allow platform JWT on profile update - Drop the non-concurrent CREATE INDEX statements from migrations/2026-04-09-103802_add_initiator_merchant_id_to_events (introduced in #11643) so deployments no longer take an ACCESS EXCLUSIVE lock on the events table when adding these indexes. - Add a new migration that recreates both indexes with CREATE INDEX CONCURRENTLY and runs outside of a transaction. - Enable allow_platform on the v1 profile_update JWT auth so platform profiles can update their own webhook endpoint configuration. Fixes bugs introduced in #11643. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diesel sends every up.sql as a single query batch, which Postgres wraps in an implicit transaction even when run_in_transaction = false. That causes CREATE INDEX CONCURRENTLY to fail with "cannot run inside a transaction block". Split the two indexes into separate migration directories, each containing a single CONCURRENTLY statement. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
XyneSpaces
approved these changes
May 25, 2026
XyneSpaces
left a comment
There was a problem hiding this comment.
Verdict: ✅ Approve
No blocking issues found.
Classification: Core (database migrations + auth routes)
Risk: Low — split migrations safely address production locking issue; auth change aligns platform permissions.
Both fixes are well-structured:
- Concurrent index builds prevent
eventstable lock during deployment - One-statement-per-migration pattern with
run_in_transaction = falsecorrectly handles Diesel's implicit transaction wrapping allow_platform: truefix unblocks legitimate platform profile updates
tsdk02
approved these changes
May 26, 2026
sai-harsha-vardhan
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Description
Two follow-up fixes for #11643 (platform-aware outgoing webhook delivery):
Build the
events.initiator_merchant_idindexes withCREATE INDEX CONCURRENTLY. The original migration2026-04-09-103802_add_initiator_merchant_id_to_eventscreated the unique and secondary indexes withoutCONCURRENTLY, which takes anACCESS EXCLUSIVElock oneventsand blocks reads/writes for the duration of the build on a large table. TheCREATE INDEXstatements have been removed from that migration and moved to two new migrations (one statement per file, since Diesel batches multiple statements in a single up.sql into one query which Postgres implicitly wraps in a transaction —CONCURRENTLYcannot run inside a transaction):2026-05-26-004557_recreate_events_initiator_merchant_id_event_id_index_concurrently2026-05-26-004558_recreate_events_initiator_merchant_id_initial_attempt_id_index_concurrentlyBoth migrations use
IF NOT EXISTSand setrun_in_transaction = false, so environments that already ran the original migration get a no-op.Allow platform JWT on the v1
profile_updateroute.JWTAuthMerchantAndProfileFromRouteonPATCH /account/:merchant_id/business_profile/:profile_idwas set toallow_platform: false, blocking a platform-account dashboard user from updating the webhook endpoint configuration on the platform profile. Flipped toallow_platform: true.Additional Changes
Database schema changes:
migrations/2026-04-09-103802_add_initiator_merchant_id_to_events/up.sql,down.sql(remove non-concurrent index statements)migrations/2026-05-26-004557_recreate_events_initiator_merchant_id_event_id_index_concurrently/(new)migrations/2026-05-26-004558_recreate_events_initiator_merchant_id_initial_attempt_id_index_concurrently/(new)Motivation and Context
Fixes bugs introduced in #11643. Tracking sub-issue: juspay/hyperswitch-cloud#16331 (sub-issue of #14710 — Platform Milestone 3).
The non-concurrent index build blocks the
eventstable on production-scale data; the JWTallow_platform: falsesetting blocks the platform onboarding flow that needs to writewebhook_detailson the platform profile.How did you test it?
diesel migration runlocally against a fresh DB and confirmed both indexes are created concurrently with no errors. (Initial single-file version surfacedCREATE INDEX CONCURRENTLY cannot run inside a transaction block; resolved by splitting into one statement per migration.)PATCH /account/:merchant_id/business_profile/:profile_idwith a platform-account JWT and awebhook_detailspayload; the request now succeeds where it previously failed authorization.Checklist
cargo +nightly fmt --allcargo clippy