Implement async partitioned index helpers
Based on a suggestion by @l.rosa in this thread, we should implement helpers for preparing/unpreparing async indexes for partitioned tables.
Context from @OmarQunsulGitlab:
Yes that's definitely a good idea. But I would suggest the following:
- Maybe different name, because this name suggests that the index is partitioned not the table. Maybe
[un]prepare_partitioned_table_async_index_by_name
.- Since we loop over the partitions and create a record for each partition, it would be good if this happens in a transactional migration so that it doesn't fail for any reason in the middle of the migration and leave the records in an inconsistent state. So maybe this helper should check that it's called from within a transaction.
We currently have the code to loop over partitions and generate index names as part of add_concurrent_partitioned_index
in lib/gitlab/database/partitioning_migration_helpers/index_helpers.rb#L27 that we could extract and refactor to maximize code re-use.