Skip to content

Add DB helper scripts for atomic database updates#1

Open
babkinvanya wants to merge 1 commit intom98:mainfrom
babkinvanya:feat/db-helper-scripts
Open

Add DB helper scripts for atomic database updates#1
babkinvanya wants to merge 1 commit intom98:mainfrom
babkinvanya:feat/db-helper-scripts

Conversation

@babkinvanya
Copy link
Copy Markdown

Summary

  • read-db.py — loads all 6 learner databases in one call (replaces 6 Read tool calls at session start). Returns combined JSON with computed fields (due_reviews_count, next_session_id, streak_active).
  • update-db.py — atomically updates all 6 databases from a single JSON session report via stdin (replaces 10+ Edit tool calls at session end). Implements SM-2 spaced repetition algorithm, streak tracking, mastery calculation, and error pattern management.
  • CLAUDE.md — documents script usage with input schema and examples so Claude knows to use scripts instead of manual edits.
  • .gitignore — adds *.json.tmp for atomic write temp files.

Why

After each learning session, Claude was manually editing 6 JSON files with 10+ sequential Edit calls — often taking longer than the lesson itself. These scripts reduce it to a single Bash call each for reading and writing, with atomic writes (.tmp + rename) and automatic pre-update backups.

Usage

# Session start: load all data
python3 .claude/hooks/read-db.py

# Session end: save results
python3 .claude/hooks/update-db.py <<'EOF_DATA'
{ "session_id": "002", "date": "2026-04-02", "duration_minutes": 20, ... }
EOF_DATA

Test plan

  • read-db.py outputs valid JSON with all 6 databases and computed fields
  • update-db.py correctly updates all 6 files from a test session payload
  • Atomic writes confirmed (.tmprename)
  • Pre-update backup created automatically
  • Used in a real learning session (session 002) — all databases updated correctly in one call

🤖 Generated with Claude Code

Two Python scripts that let Claude update/read all 6 learning databases
with a single Bash call instead of 10+ manual Edit operations per session.

- read-db.py: loads all databases + computes due reviews, next session ID
- update-db.py: atomic update of all 6 DBs with SM-2 spaced repetition
- CLAUDE.md: document script usage with input schema examples
- .gitignore: add *.json.tmp for atomic write temp files

Co-Authored-By: Claude Opus 4.6 <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

None yet

Development

Successfully merging this pull request may close these issues.

1 participant