Skip to content

fix(webhooks): build events indexes concurrently and allow profile update#12463

Open
apoorvdixit88 wants to merge 7 commits into
mainfrom
cover-webhooks-bugs
Open

fix(webhooks): build events indexes concurrently and allow profile update#12463
apoorvdixit88 wants to merge 7 commits into
mainfrom
cover-webhooks-bugs

Conversation

@apoorvdixit88
Copy link
Copy Markdown
Contributor

@apoorvdixit88 apoorvdixit88 commented May 25, 2026

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Two follow-up fixes for #11643 (platform-aware outgoing webhook delivery):

  1. Build the events.initiator_merchant_id indexes with CREATE INDEX CONCURRENTLY. The original migration 2026-04-09-103802_add_initiator_merchant_id_to_events created the unique and secondary indexes without CONCURRENTLY, which takes an ACCESS EXCLUSIVE lock on events and blocks reads/writes for the duration of the build on a large table. The CREATE INDEX statements 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 — CONCURRENTLY cannot run inside a transaction):

    • 2026-05-26-004557_recreate_events_initiator_merchant_id_event_id_index_concurrently
    • 2026-05-26-004558_recreate_events_initiator_merchant_id_initial_attempt_id_index_concurrently

    Both migrations use IF NOT EXISTS and set run_in_transaction = false, so environments that already ran the original migration get a no-op.

  2. Allow platform JWT on the v1 profile_update route. JWTAuthMerchantAndProfileFromRoute on PATCH /account/:merchant_id/business_profile/:profile_id was set to allow_platform: false, blocking a platform-account dashboard user from updating the webhook endpoint configuration on the platform profile. Flipped to allow_platform: true.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

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 events table on production-scale data; the JWT allow_platform: false setting blocks the platform onboarding flow that needs to write webhook_details on the platform profile.

How did you test it?

  • Ran diesel migration run locally against a fresh DB and confirmed both indexes are created concurrently with no errors. (Initial single-file version surfaced CREATE INDEX CONCURRENTLY cannot run inside a transaction block; resolved by splitting into one statement per migration.)
  • Manually verified the JWT auth change by calling PATCH /account/:merchant_id/business_profile/:profile_id with a platform-account JWT and a webhook_details payload; the request now succeeds where it previously failed authorization.

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

…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>
@apoorvdixit88 apoorvdixit88 requested a review from a team as a code owner May 25, 2026 19:23
@hyperswitch-bot hyperswitch-bot Bot added the M-database-changes Metadata: This PR involves database schema changes label May 25, 2026
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>
@apoorvdixit88 apoorvdixit88 self-assigned this May 25, 2026
@apoorvdixit88 apoorvdixit88 changed the title fix(webhooks): build events indexes concurrently and allow platform JWT on profile update fix(webhooks): build events indexes concurrently and allow profile update May 25, 2026
@apoorvdixit88 apoorvdixit88 added the S-test-ready Status: This PR is ready for cypress-tests label May 25, 2026
Copy link
Copy Markdown

@XyneSpaces XyneSpaces left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 events table lock during deployment
  • One-statement-per-migration pattern with run_in_transaction = false correctly handles Diesel's implicit transaction wrapping
  • allow_platform: true fix unblocks legitimate platform profile updates

@github-actions github-actions Bot removed the S-test-ready Status: This PR is ready for cypress-tests label May 26, 2026
@apoorvdixit88 apoorvdixit88 added the S-test-ready Status: This PR is ready for cypress-tests label May 26, 2026
@github-actions github-actions Bot removed the S-test-ready Status: This PR is ready for cypress-tests label May 26, 2026
@apoorvdixit88 apoorvdixit88 added the S-test-ready Status: This PR is ready for cypress-tests label May 26, 2026
@github-actions github-actions Bot removed the S-test-ready Status: This PR is ready for cypress-tests label May 27, 2026
@apoorvdixit88 apoorvdixit88 added the S-test-ready Status: This PR is ready for cypress-tests label May 29, 2026
@github-actions github-actions Bot removed the S-test-ready Status: This PR is ready for cypress-tests label May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-core Area: Core flows C-bug Category: Bug M-database-changes Metadata: This PR involves database schema changes T-Payment Methods & Routing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants