Skip to content

Conversation

@alachaum
Copy link

@alachaum alachaum commented Mar 3, 2025

Hi @rkrage , thanks for maintaining this gem. It really makes using partitioning a breeze 🥇

This PR adds support for the if_not_exists: true option when using add_index_on_all_partitions, similar to what Rails provides on add_index. The if_not_exists gets cascaded to the sub-tables, meaning that the whole operation can be resumed where it was left off in the event of an error, timeout etc.

Rationale

We're in a situation where we need to run long-running migrations in background jobs, which also means we need to deal with job timeouts. And because we have a fair amount of data, those timeouts are expected (since the concurrently option is synchronous from a connection perspective). Restarting a migration from scratch on error or timeout is not a viable option.

The if_not_exists approach, combined with the concurrently option, gives us the ability to have resilient migration jobs that resume themselves and create indexes progressively.

We already use this approach with regular tables, and it would be great to have the same with partitioned tables 🚀

@alachaum alachaum force-pushed the support-index-if-not-exists branch from ab81e0b to 90daab1 Compare December 2, 2025 17:42
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.

1 participant