Skip to content

feat: add --disable-concurrent-index-ops command-line flag - #223

Closed
geeknonerd wants to merge 1 commit into
stripe:mainfrom
geeknonerd:feature/disable-concurrent-index
Closed

geeknonerd wants to merge 1 commit into
stripe:mainfrom
geeknonerd:feature/disable-concurrent-index

Conversation

@geeknonerd

Copy link
Copy Markdown
Contributor

Description

This PR introduces a new flag, --disable-concurrent-index-ops, allowing users to disable the use of CONCURRENTLY in CREATE INDEX and DROP INDEX
statements. Previously, concurrent index operations were always used for non-partitioned tables, which may not be suitable for all environments or use
cases.

Motivation

Some environments or scenarios require simpler DDL statements without the CONCURRENTLY keyword:

  • Testing environments where downtime is acceptable and simpler SQL is preferred
  • Development workflows that need predictable, synchronous index operations
  • Integration with systems that don't support or have limitations with concurrent index operations
  • Debugging scenarios where non-concurrent operations provide clearer behavior

By making concurrent operations configurable while keeping them as the safe default, we can accommodate more diverse deployment scenarios while
maintaining the tool's focus on minimal-downtime migrations.

Changes Made

  • Core Implementation: Added disableConcurrentIndexOps field to planOptions in pkg/diff/plan_generator.go
  • API: Created WithDisableConcurrentIndexOps() PlanOpt function for programmatic use
  • CLI: Added --disable-concurrent-index-ops command-line flag in cmd/pg-schema-diff/plan_cmd.go
  • Index Creation: Modified index creation logic in pkg/diff/sql_generator.go to conditionally use CONCURRENTLY
  • Index Deletion: Updated index deletion logic to conditionally use CONCURRENTLY
  • Safety: Added appropriate hazard warnings (ACQUIRES_ACCESS_EXCLUSIVE_LOCK) when concurrent operations are disabled
  • Timeouts: Adjusted statement timeouts (3s vs 20m) based on operation type
  • Documentation: Updated CLAUDE.md with usage examples and implementation details

Testing

  • ✅ All existing unit tests pass without regressions
  • ✅ Verified default behavior remains unchanged (still uses CONCURRENTLY)
  • ✅ Confirmed new flag correctly removes CONCURRENTLY from both CREATE and DROP INDEX statements
  • ✅ Validated proper hazard warnings are displayed when concurrent operations are disabled
  • ✅ Tested with both pretty and JSON output formats
  • ✅ Verified help documentation displays the new flag correctly

Example Usage

Default behavior (unchanged):
pg-schema-diff plan --from-dsn "..." --to-dir ./schema

Generates: CREATE INDEX CONCURRENTLY idx_name ON table(column);

With new flag:
pg-schema-diff plan --from-dsn "..." --to-dir ./schema --disable-concurrent-index-ops

Generates: CREATE INDEX idx_name ON table(column);

Backward Compatibility

This change is fully backward compatible. The default behavior remains unchanged, and the new flag is opt-in only. Existing scripts and workflows will
continue to work exactly as before.

@cla-assistant

cla-assistant Bot commented Jul 29, 2025 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Jul 29, 2025

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@geeknonerd geeknonerd changed the title Add --disable-concurrent-index-ops command-line flag feat: add --disable-concurrent-index-ops command-line flag Jul 29, 2025
@bplunkett-stripe

Copy link
Copy Markdown
Contributor

Going to push this PR into the upstream through this PR!. Based off your branch! Thanks for the contributions here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants