Skip to content

Conversation

@mdgoldberg
Copy link
Owner

@mdgoldberg mdgoldberg commented Jan 19, 2026

Summary

Adds a new database crate that enables SQLite persistence for recording games, players, and actions. Integrates with the simulation crate to automatically track all game activity.

Changes

New Crate: database

  • Models: Player, Game, GameResult, Action, FailedWrite records
  • Repository: DatabaseRecorder with async sqlx operations
  • Config: Database URL from CLI, env, or YAML config
  • Retry Logic: Exponential backoff for write operations

Integration

  • Simulation crate now records all game events to database
  • Player registration with UUID-based identification
  • Configurable database URL (sqlite::memory: for testing, sqlite:file.db for persistence)

Documentation

  • Added comprehensive README with usage examples
  • Added config.sample.yaml with 5-player example
  • Added AGENTS.md docs for simulation and types crates

Tests

  • Added integration tests for game execution
  • Added unit tests for database operations

Breaking Changes

  • GameState::new now accepts (Uuid, name, strategy) tuples instead of (name, strategy)

Usage

# In-memory (no persistence)
cargo run --bin run_simulation -- --config config.yaml

# Persistent SQLite database
cargo run --bin run_simulation -- --config config.yaml --database sqlite:roosevelt.db

Commits

  • chore: update .gitignore for database and sqlx cache
  • docs: add comprehensive README with usage examples
  • chore: add database crate to workspace and update dependencies
  • feat: add database crate for game persistence
  • docs: add sample configuration file
  • feat: integrate database into simulation crate
  • refactor: update types crate for database integration
  • test: add integration tests and update project docs
  • fix: remove redundant tokio import

Matt Goldberg added 9 commits January 19, 2026 03:13
- Add trailing slash to target/ for consistency
- Add config.yaml to ignore user configs
- Add sqlite* to ignore SQLite database files
- Add .sqlx/ to ignore sqlx macro cache directory
- Add full project overview explaining Roosevelt card game simulation
- Document quick start with prerequisites and installation steps
- Add YAML configuration examples for various player setups
- Document database persistence features and configuration priority
- Explain game rules, roles, and card passing mechanics
- List available AI strategies (default, random, input)
- Document command-line options and database schema
- Update AGENTS.md to reflect project structure changes
- Add database crate as new workspace member
- Define shared workspace dependencies for all crates
- Include sqlx, r2d2, tokio, async-trait, and other DB-related deps
- Update Cargo.lock with all transitive dependencies
Add new database crate using sqlx with SQLite support for persisting:
- Players: unique IDs, names, and creation timestamps
- Games: start/end times, deck seeds, player order, config snapshots
- Game results: finishing places and role assignments
- Actions: all game actions with turn order and phase tracking
- Failed writes: error tracking for debugging

Features:
- Connection pooling with r2d2 (max 20 connections)
- Retry logic with exponential backoff for writes
- Async trait for game recording operations
- Migration-based schema management
Add config.sample.yaml with 5-player example configuration showing:
- Player names and strategy selections
- Delay configuration for visualization
- Database URL configuration
Update simulation crate to use database persistence:
- Add database dependency to Cargo.toml
- Modify run_game to accept GameRecorder trait for recording games
- Record all game actions (plays, sends, passes) with turn order and phase
- Record game results with finishing places and roles
- Add player registration flow with database lookup
- Support configurable database URL via CLI, env, or YAML config
Changes to support UUID-based player identification:
- CardPlay::Ord now compares by size first (Single < Pair < Triple < Quad)
- GameState::new accepts (Uuid, name, strategy) tuples for player inputs
- Fix inverted is_first_cardplay logic (was checking all instead of any)
- Add PlayerState::new_with_id constructor with explicit UUID
- Export Hand trait from lib.rs for hand detection utilities
Add integration tests for simulation crate:
- test_run_game_with_default_strategies: 3-player game with default AI
- test_run_game_with_mixed_strategies: mix of default and random AI
- test_run_game_with_delay: verify delay functionality works
- test_multiple_games: consecutive games with new player inputs

Add database unit tests:
- test_record_and_retrieve_player
- test_record_game, test_record_action, test_record_game_result
- test_finish_game, test_noop_recorder

Update project documentation:
- simulation/AGENTS.md: Simulation crate overview
- types/AGENTS.md: Types crate documentation

Fix clippy warnings:
- Remove redundant tokio imports
- Rename tests module to database_tests to fix module-inception
The #[tokio::main] attribute already handles tokio imports, so
the explicit  statement is unnecessary.
Matt Goldberg added 2 commits January 19, 2026 22:55
Add WAL journal mode and normal synchronous mode to SQLite connection options
for improved concurrency and balanced performance. Increase cache size to -64000
pages (approximately 64MB) to enhance performance during bulk write operations,
preventing excessive disk I/O and improving overall database throughput.

This change addresses performance bottlenecks identified in bulk data operations
by leveraging SQLite's WAL mode for concurrent readers/writers and optimizing
memory usage for write-heavy workloads.
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.

2 participants