feat(database): disable eager collection creation for all schemas#1554
feat(database): disable eager collection creation for all schemas#1554ChrisPdgn wants to merge 3 commits into
Conversation
That’s only true for indexes that are still left in modelOptions.indexes after schemaConverter runs. Single-field indexes get peeled out of modelOptions.indexes and moved onto the field (SchemaConverter.convertModelOptionsIndexes), and field-level unique / index never go through createIndexes() at all. They used to rely on Mongoose autoIndex. So with autoIndex: false on every schema, those indexes aren’t created on a fresh MongoDB. Compound ones still work. Quick examples: ChatRoom: { fields: ['participants'] } gets moved to the field; only { fields: ['participants', 'deleted'] } hits createIndexes() I checked this with Mongoose too: with autoIndex: false, path indexes show up in schema.indexes() but tagged _autoIndex: false, so they won’t be built. There’s also no ensureIndexes / syncIndexes fallback elsewhere in the adapter. This won’t show up on DBs that already had the indexes from before, but it’s a real regression for fresh environments / new schemas. I think we should keep autoCreate: false, but either:
|
With autoIndex disabled, field-level unique/index definitions and single-field indexes moved onto fields by SchemaConverter were not being created on fresh databases. Create them explicitly from the compiled Mongoose schema while skipping the default _id index so schemas without other indexes remain lazy. Co-authored-by: Cursor <[email protected]>
Align explicit field-index creation with MongoDB IndexSpecification typing so the database module builds on v0.16.x. Co-authored-by: Cursor <[email protected]>
Summary of changesThis PR disables eager MongoDB collection creation in the Mongoose adapter while preserving correct index behavior on fresh databases. 1. Lazy collection creationIn
This stops Mongoose from creating empty collections at schema registration time. Collections are created lazily on first write, or when an index is explicitly created. 2. Explicit field-level index creationDisabling To fix that, Important safeguards:
Expected behavior
No Conduit schema migration is expected; |
Summary
autoCreate: falseandautoIndex: falseon every Mongoose schema in the database adapter, not just views.createIndexes()during schema registration.Test plan
findMany/findOneagainst a schema whose collection has not been created yet and confirm empty results are returned without errors.