Skip to content

🐛(backend) do not fail the parent path index migration on an existing index - #874

Open
NathanVss wants to merge 1 commit into
mainfrom
fix/item-parent-path-idx-migration
Open

NathanVss wants to merge 1 commit into
mainfrom
fix/item-parent-path-idx-migration

Conversation

@NathanVss

@NathanVss NathanVss commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Until item_parent_path_idx is valid, the queries relying on it read the whole item table. On preprod the new code served requests while the index was still being built: item creation took 17s and the migration job died after 33 minutes, leaving an invalid index.

On large databases the index must therefore be created by hand before the release is deployed, but the migration then fails with relation "item_parent_path_idx" already exists.

Proposal

Migration 0031 now uses a reusable AddIndexConcurrentlyIfMissing operation (core/utils/migrations.py), which looks the index up before building it:

  • no index: build it, as before
  • valid index: nothing to do
  • invalid index (interrupted concurrent build): drop it and build it again

Deploying on a large database

Before deploying, run and check that indisvalid is true:

CREATE INDEX CONCURRENTLY "item_parent_path_idx"
ON "drive_item" ((subpath("path", 0, nlevel("path") - 1)));

SELECT indisvalid FROM pg_index
WHERE indexrelid = 'item_parent_path_idx'::regclass;

… index

Until the parent path index is valid, the queries relying on it read the
whole item table: deploying the code while the index is still being built
overloads the database. On large databases the index is thus created by
hand before the release, and the migration failed on its name.

The migration now skips the build when a valid index exists. An invalid
one, left behind by an interrupted concurrent build, also made it fail:
it is dropped and built again. The operation doing so is not tied to this
index, for the next migrations building one concurrently to reuse it.
@NathanVss
NathanVss force-pushed the fix/item-parent-path-idx-migration branch from 4c7f55b to ec12209 Compare October 9, 2026 16:28
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@NathanVss
NathanVss requested a review from kernicPanel October 9, 2026 16:30

This branch has not been deployed

No deployments
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