Skip to content

Issue #1243: fix: create person_identifier_idx whether or not the MongoDB instance is seeded - #1307

Open
dereck-symmetry wants to merge 1 commit into
mainfrom
issue-1243-index-independent-of-seeding
Open

dereck-symmetry wants to merge 1 commit into
mainfrom
issue-1243-index-independent-of-seeding

Conversation

@dereck-symmetry

Copy link
Copy Markdown
Contributor
Description of Change

Problem. person_identifier_idx, the index behind the Query Cache's identity filter (query(), update(), save()), was created only as a side effect of seeding. projects/mongodb/entrypoint.sh did exit 0 when SEED_DATA_KEY was unset, before the index step, so an unseeded instance came up with no index at all. This is case 2 in #1243.

Solution. The seeding block becomes if/else instead of an early exit 0. Seeding is still conditional on SEED_DATA_KEY. Index creation now always runs, and still after the import when there is one, because mongoimport --drop drops the collection along with its indexes. git diff -w shows the real change is 3 lines plus a comment; the rest is re-indentation into the else. The entrypoint.sh row in projects/mongodb/README.md now mentions the index.

When the collection doesn't exist yet, createIndex creates it, so an unseeded instance comes up with an empty person collection that already has the index.

Why this approach (option 1 in the issue) and not a Query Cache startup create_index (option 2). Deployed MongoDB has no persistent storage: the EFS MountPoints in cloudformation/mongodb-taskdef-includes.yml are commented out. Every ECS task starts from an empty data dir and reruns the entrypoint, so on dev and demo the entrypoint alone covers every case, including an unseeded one. The startup ensure would add a MongoDB dependency to the Query Cache's startup path (it has no lifespan today) and would need a failure-mode decision. We're leaving that out until it's actually needed.

Limitation. This is why the PR says Refs, not Closes. The issue's first acceptance criterion says an instance created before #1242 should end up with the index. Docker runs /docker-entrypoint-initdb.d/ only on an empty data dir, so a local named volume that already exists (for example mongo_data in development/advisor-demo-1org) won't get the index from this change. The fix there is docker compose down -v. Case 3 in the issue (a MongoDB not built from projects/mongodb) is also not covered. Both would need option 2. The second criterion (existence doesn't depend on SEED_DATA_KEY) is met.

How reviewers should test it.

tar -C projects/mongodb -c . | docker build -t mongodb:1243 -
# unseeded -- on main this gives "ns does not exist: LIF.person"
docker run -d --name m1243 -e MONGO_DB=LIF -e MONGO_COLLECTION=person -e MONGO_HOST=mongodb-org1 mongodb:1243
# wait for the second "Waiting for connections" in `docker logs m1243`, then:
docker exec m1243 mongosh --quiet LIF --eval 'db.person.getIndexes().map(i => i.name)'
# -> [ '_id_', 'person_identifier_idx' ]

Repeat with -e SEED_DATA_KEY=advisor-demo-org1 to check the seeded path is unchanged: 4 docs plus the index.

Related Issues

Refs #1243
Refs #1131

Type of Change
  • Bug fix (non-breaking change which fixes an issue)
  • Infrastructure/deployment change
Project Area(s) Affected
  • projects/
  • Documentation (docs/, READMEs, ARCHITECTURE.md, CLAUDE.md)

Checklist
  • commit message follows commit guidelines (see commitlint.config.mjs)
  • pre-commit hooks have been run successfully
  • configuration changes: relevant folder README updated
Testing
  • Manual testing performed

A fresh container each time, built from projects/mongodb, with MONGO_HOST=mongodb-org1 (a service name that doesn't resolve, the same shape as ECS):

Case main This branch
SEED_DATA_KEY unset no collection, no index 0 docs, [_id_, person_identifier_idx]
SEED_DATA_KEY=advisor-demo-org1 4 docs, [_id_, person_identifier_idx] 4 docs, [_id_, person_identifier_idx]
SEED_DATA_KEY=advisor-demo-org3 not run 4 docs, [_id_, person_identifier_idx]

No automated test is added. The entrypoint is a shell init script that only runs inside the MongoDB image, and the one suite that checks the index (integration_tests/test_01_mongodb.py) is local-only and not run by CI. It asserts the index on the seeded path, which this change doesn't alter. pre-commit run --files passed on both changed files, and bash -n passed on the script.

Additional Notes

🤖 Generated with Claude Code

…goDB instance is seeded

The entrypoint exited before the index step when SEED_DATA_KEY was unset,
so an unseeded instance came up with no index (and no collection). Seeding
stays conditional; index creation now always runs, still after the import
when there is one, because mongoimport --drop drops the collection's indexes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant