Admin API for data cleanup, so corrections no longer need direct database access
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 15/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- mongodb, typescript
- 領域
- api, authorization, backend, database
調査の方向性
This is a multi-part design proposal, not one change. Start with the existing PATCH /instrument-records/:id and subject DELETE routes, and with the audit logging in #1889, which the issue calls a prerequisite. Item 7 (soft delete) is marked as needing a decision, so it should be settled before work starts. Done means the maintainers have split the proposal into smaller issues, each with unit and e2e tests.
索引モデルが issue の本文から書いたものです。
説明
Context
An admin cleaned up the data on a production instance (v2.5.2): about 28,000 duplicate bulk-uploaded records, test subjects, empty sessions, and a year typo in record dates. Some of the work was possible through the API. The rest needed direct mongosh access to the database, which is risky, needs shell access to the host, and leaves no trace in the application. This issue lists what the API should offer so the next cleanup needs no direct database access.
Related: #1883 (no session delete), #1884 (upload duplicates), #1887 (future dates), #1889 (writes are not audited).
What had to be done outside the API, or was hard through it
| Task | What we had to do | Why |
|---|---|---|
| Delete sessions left empty after record deletes (86 sessions) | deleteMany in mongosh |
No session delete endpoint (#1883) |
Correct the date of 17 records and their sessions |
updateMany in mongosh |
PATCH /instrument-records/:id accepts only data; there is no session update |
| Move records that were saved on the wrong subject (same mouse, with and without a group) | Not possible; the records were deleted instead | PATCH cannot change subjectId |
| Delete 847 subjects and 37 records | 884 single DELETE calls |
No bulk delete. The run hit HTTP 429 after about 250 calls and a 60 s network timeout later, so it needed retry and resume logic in a client script |
| Find duplicates, empty sessions, future dates, data outside a group | Download every subject, session and record (about 36 MB of JSON) and analyse it offline | No integrity report |
| Back up before each change, restore if needed | mongodump over ssh; a custom mongosh script for partial restore |
No admin export or restore by ID |
Audit gap: after all these API deletes, GET /audit/logs?action=DELETE returns 0 entries, because subject, session and instrument-record writes are not audited. This is tracked in #1889. Direct database edits are not audited either, which is one more reason to replace them with the endpoints below.
Proposal
-
Audit logging (#1889). Every new endpoint below must write audit entries. #1889 adds them for the existing subject, session, instrument-record and group writes, so it is a prerequisite for this issue.
-
Session endpoints:
DELETE /sessions/:id, refused while records or assignments use the session (see #1883), andPATCH /sessions/:idfordate. -
Record correction: allow
PATCH /instrument-records/:idto changedate, andsubjectIdto another subject in the same group, with access checks and an audit entry. The record's session follows: either update it if no other record uses it, or create a new one. -
Bulk delete with dry run:
POST /subjects/bulk/deleteandPOST /instrument-records/bulk/deletethat take a list of IDs anddryRun: true|false. A dry run returns exactly what would be removed (subjects, records, sessions, files). A real run executes in one transaction (or in documented chunks), removes sessions left empty, and writes one audit entry per entity. This replaces hundreds of rate-limited calls. -
Admin integrity report:
GET /admin/integrity(ADMIN only) returning counts and IDs for:- exact duplicate records (same subject, instrument, date and data)
- sessions with no record or assignment
- record or session dates in the future
- records or subjects with no group
- subjects with no records
- subject IDs that differ only by case or punctuation
A web page under Admin could show it.
-
Admin export and restore by ID: an ADMIN-only download of subjects, sessions and records with their original IDs, and an import that inserts only documents whose ID is missing (it never overwrites). Then an admin can restore deleted data without database access.
-
Needs decision: soft delete. As an alternative to items 4 and 6, mark subjects and records as deleted with a retention period, list them in a trash view, and purge them later.
Each change needs a unit test and an e2e test.
- 主要言語
- TypeScript
- スター
- 119
- フォーク
- 19
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 61
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
DouglasNeuroInformatics/OpenDataCapture のほかの issue
-
Area: API Bug Difficulty: Low Priority: Low
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
DouglasNeuroInformatics/OpenDataCapture#1937 ·
メンテナーはふだん 1 日以内に返信
-
Area: Infrastructure Bug Difficulty: Low Priority: Medium Security
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
DouglasNeuroInformatics/OpenDataCapture#1916 ·
メンテナーはふだん 1 日以内に返信
-
Area: Infrastructure Chore Difficulty: Low Priority: Medium
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
DouglasNeuroInformatics/OpenDataCapture#1835 ·
メンテナーはふだん 1 日以内に返信
-
Area: Instruments Bug Difficulty: Low Priority: Low
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
DouglasNeuroInformatics/OpenDataCapture#1824 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Completing a series instrument logs a TypeError "Cannot read properties of undefined (reading 'kind')"対応中かも @SAY-5 が 3 日前に担当しました。 オープンArea: Shared Bug Difficulty: Low Priority: Low
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
DouglasNeuroInformatics/OpenDataCapture#1813 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
DouglasNeuroInformatics/OpenDataCapture の issue をすべて見る
似ている issue
-
infra needs-triage
難易度 2/5 1時間未満 初心者へのやさしさ 82/100
LucasSantana-Dev/Lucky#3331 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
kOaDT/oss-oopssec-store#381 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
nocobase/nocobase#11669 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
iOS: Clear Context (/clear) and model picker fallback use negative agent check instead of isClaudeオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信