Skip to content

Add --wait option to odm:schema:create and odm:schema:update - #3028

Open
GromNaN wants to merge 1 commit into
doctrine:2.17.xfrom
GromNaN:feature-3026-schema-create-wait
Open

Add --wait option to odm:schema:create and odm:schema:update#3028
GromNaN wants to merge 1 commit into
doctrine:2.17.xfrom
GromNaN:feature-3026-schema-create-wait

Conversation

@GromNaN

@GromNaN GromNaN commented Jul 3, 2026

Copy link
Copy Markdown
Member

Closes #3026.

Search indexes are built asynchronously by the server: odm:schema:create and odm:schema:update return before the index is queryable. Scripts that need the index to be ready (CI seeding, deployments, integration tests) had to reimplement the wait around SchemaManager::waitForSearchIndexes(). This matters more with autoEmbed (#3024), where the initial embedding backfill through Voyage AI can take minutes on non-trivial collections.

Both commands now accept a --wait option with an optional value:

$ bin/mongodb odm:schema:create --search-index --wait
$ bin/mongodb odm:schema:update --wait=1minute
$ bin/mongodb odm:schema:create --search-index --wait="30 seconds"
$ bin/mongodb odm:schema:create --search-index --wait=5000

The value is a duration string parsable by strtotime() (30 seconds, 1minute, 1 hour) or a positive integer of milliseconds. When --wait is passed without a value, it falls back to the SchemaManager default of 10 seconds. The wait is skipped automatically when no mapped class declares a search index.

Documentation has been updated in docs/en/reference/search-indexes.rst and the vector-search cookbook, including a note that waiting reports index readiness only, not that the background indexer has caught up with documents inserted after index creation.

@GromNaN
GromNaN requested a review from paulinevos July 3, 2026 13:45
@GromNaN GromNaN added the Feature label Jul 3, 2026
@GromNaN GromNaN changed the title Add --wait option to odm:schema:create and odm:schema:update Add --wait option to odm:schema:create and odm:schema:update Jul 3, 2026
@GromNaN GromNaN added this to the 2.17.0 milestone Jul 3, 2026
@GromNaN

GromNaN commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

I'm now thinking that the command should not return 0 when the --wait option is used and the wait timed out.

Edit: this is already the case. In case of timeout, a MongoDBException is thrown, and the command return code is 255.

Search indexes are built asynchronously by the server: create and
update return before the index is queryable. Scripts that need the
index to be ready (CI seeding, deployments, integration tests) had
to reimplement the wait around SchemaManager::waitForSearchIndexes().

Expose it as a --wait option on both commands. The value is a
duration string parsable by strtotime() ("30 seconds", "1minute",
"1 hour") or a positive integer of milliseconds. When --wait is
passed without a value, it falls back to the SchemaManager default
of 10 seconds. The wait is skipped automatically when no mapped
class declares a search index.

Refs doctrine#3026
@GromNaN
GromNaN force-pushed the feature-3026-schema-create-wait branch from 9b8ae0a to 163a867 Compare July 9, 2026 13:54

$ php mongodb.php odm:schema:create --search-index --wait=1minute

The value accepts a duration such as ``30 seconds``, ``1minute`` or

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this could be clarified as it seems to be a maximum duration. I'm assuming that the script stops when the index is ready and doesn't wait out the remainder of the duration.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, that's a wait timeout, can you update the description and merge?

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

odm:schema:create has no option to wait for search/vector indexes to become READY

2 participants