Add MariaDB database support for storing transaction data

Introduces a new database layer to persist CSV transaction data in MariaDB,
enabling both invoicing and sales reporting queries. This replaces the
previous file-to-file-only processing.

Changes:
- Add sqlx, tokio, toml, anyhow, bigdecimal dependencies to Cargo.toml
- Create config module for TOML-based configuration (database credentials)
- Create db module with connection pool, models, and repository
- Create commands module with 'import' subcommand for CSV ingestion
- Refactor main.rs to use subcommand architecture (import/generate)
- Add migration SQL file for manual database schema creation

Schema (3 tables):
- customers: customer_number, card_report_group (1=fleet, 3/4=retail)
- cards: card_number, card_type, customer_id (nullable for anonymous)
- transactions: full transaction data with FK to cards/customers

Usage:
  cargo run -- import <csv-file>   # Import to database
  cargo run -- generate <csv> <dir>  # Generate HTML invoices (unchanged)

Configuration:
  cp config.example.toml config.toml  # Edit with database credentials
  mysql < migrations/001_initial_schema.sql  # Create database first
This commit is contained in:
2026-04-02 06:33:38 +02:00
parent 39b62014b0
commit 9daa186ff6
13 changed files with 762 additions and 93 deletions

View File

@@ -5,6 +5,11 @@ edition = "2021"
[dependencies]
askama = "0.15.5"
chrono = "0.4.44"
chrono = { version = "0.4.44", features = ["serde"] }
csv = "1.4.0"
serde = "1.0.228"
serde = { version = "1.0.228", features = ["derive"] }
sqlx = { version = "0.8", features = ["runtime-tokio", "mysql", "chrono", "bigdecimal"] }
tokio = { version = "1", features = ["full"] }
toml = "0.8"
anyhow = "1"
bigdecimal = { version = "0.4", features = ["serde"] }