D1 Database
The initial migration creates a multi-table SQLite/D1 schema:
playersgamesgame_playersplayer_game_factsround_summariesplayer_mode_summaryplayer_mode_dailyglobal_daily_statsranking_snapshotssource_indexesingest_jobsparse_errorscoverage_days
The schema uses unique keys for idempotent loading:
players.normalized_namegames.tenhou_log_idgame_players(game_id, seat)game_players(game_id, player_id)player_game_facts(player_id, game_id)round_summaries(game_id, round_index)source_indexes(source_name, file_name)ingest_jobs(job_type, job_key)
Run the migration locally with:
sqlite3 :memory: ".read libs/d1-schema/migrations/0001_initial.sql" "PRAGMA table_list;"
For the Wrangler local D1 used by pnpm api:dev:
pnpm api:migrate:local
pnpm api:seed:local
The seed inserts one small game and precomputed summaries so local API routes can be tested without fetching Tenhou data or running runtime aggregation.