A newly set-up instance runs without its MongoDB indexes until the API restarts, because setup drops the database after boot built them
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 74/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- mongodb, nodejs, typescript
Hướng nghiên cứu
Read apps/api/src/setup/setup.service.ts and the ensureDatabaseIndexes implementation in apps/api/src/core/prisma.ts; trace the database-drop path used by initApp and delete. Start with apps/api/src/setup/__tests__/setup.service.test.ts, then use the integration harness in apps/api/test/suites/ to verify that indexes exist after setup. Done means indexes are restored after a drop and before admin creation, with the relevant tests passing.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
A newly set-up instance runs with no MongoDB indexes until the API restarts. ensureDatabaseIndexes builds every index in DATABASE_INDEXES once, when the Prisma client is created at boot. SetupService.initApp, which serves POST /v1/setup, then drops the whole database before it creates the admin. Dropping a database also drops its indexes. Every collection written after that is recreated on first insert with only _id_.
Until the next restart, the instance enforces none of the schema's unique constraints: UserModel.username, GroupModel.name, InstrumentRepoModel.url and PermissionSetModel.name, plus the InstrumentRecordModel.assignmentId index. Every query those indexes exist for scans the whole collection. The services check for duplicates before they insert (for example GroupsService.create calls exists({ name })), so a duplicate needs two concurrent requests. The index is the only thing that stops that race. A Docker deployment that is set up once and never restarted stays in this state indefinitely. The same thing happens on every re-initialisation in development, which initApp allows when NODE_ENV=development.
The Playwright stack runs this way too: testing/src/global/setup.spec.ts posts /v1/setup after the API has booted, so no e2e test ever runs against the indexes.
Where
apps/api/src/setup/setup.service.ts:99 (initApp) and :49 (delete, test-only) both call:
private async dropDatabase(): Promise<void> {
const result = await this.prismaClient.$runCommandRaw({ dropDatabase: 1 });
...
}
apps/api/src/core/prisma.ts:190: the only call to ensureDatabaseIndexes, in the client factory, right after $connect():
await client.$connect();
await ensureDatabaseIndexes(client);
Introduced with startup index creation in 672eaab19 (v2.2.3). Every instance set up since then started without indexes and got them only at its first restart.
Reproduce
- Start the API on an empty database (
pnpm dev:testinapps/apiwill do). - Before setup, list the indexes on
UserModel: the uniqueUserModel_username_keyis there. POST /v1/setupwith valid$InitAppOptions.- List the indexes on
UserModelagain.
Actual: only _id_. The same holds for every other collection in DATABASE_INDEXES.
Expected: setup leaves the database with every index ensureDatabaseIndexes builds at boot.
Tests
apps/api/src/setup/__tests__/setup.service.test.ts:it('should rebuild the database indexes after dropping the database, so a newly set-up instance enforces its unique constraints'). Assert the order: drop, then indexes, then the admin is created.apps/api/test/suites/: boot the app,POST /v1/setup, then runlistIndexesonUserModelandGroupModelthrough the Prisma client and expect the unique indexes. Unit tests mock Prisma, so only this harness shows what a realdropDatabasedoes.- E2E: no route exposes indexes. One option is a spec that sends two concurrent
POST /v1/groupsrequests with the same name after the global setup and expects exactly one group to be created. Today both can succeed. Whether that is reliable enough, or whether the integration suite counts as the e2e coverage here, is the implementer's call to raise in the PR.
Suggested fix
Rebuild the indexes inside dropDatabase, right after the drop succeeds, so every path that drops the database, delete included, restores them. src/core/prisma.ts already exports ensureDatabaseIndexes, and it takes a RawCommandRunner, which the injected client satisfies. Running it before createAdmin also means the admin and demo inserts happen with the indexes in place.
Found while working on #1571 (PR #1878).
- Ngôn ngữ chính
- TypeScript
- Star
- 119
- Fork
- 19
- Merge trung bình
- 1 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 61
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của DouglasNeuroInformatics/OpenDataCapture
-
Area: API Bug Difficulty: Low Priority: Low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
DouglasNeuroInformatics/OpenDataCapture#1937 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Area: Infrastructure Bug Difficulty: Low Priority: Medium Security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
DouglasNeuroInformatics/OpenDataCapture#1916 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Area: Infrastructure Chore Difficulty: Low Priority: Medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
DouglasNeuroInformatics/OpenDataCapture#1835 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Area: Instruments Bug Difficulty: Low Priority: Low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
DouglasNeuroInformatics/OpenDataCapture#1824 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Completing a series instrument logs a TypeError "Cannot read properties of undefined (reading 'kind')"Có thể đã có người làm @SAY-5 đã nhận 3 ngày trước. Đang mởArea: Shared Bug Difficulty: Low Priority: Low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
DouglasNeuroInformatics/OpenDataCapture#1813 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của DouglasNeuroInformatics/OpenDataCapture
Issue tương tự
-
infra needs-triage
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 82/100
LucasSantana-Dev/Lucky#3331 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
kOaDT/oss-oopssec-store#381 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
nocobase/nocobase#11669 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
iOS: Clear Context (/clear) and model picker fallback use negative agent check instead of isClaudeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày