Files
pawctioneer-bot/backlog/tasks/task-003 - Create-core-database-models-and-structs.md
Dylan Knutson 32dca5f4de refactor: Convert MoneyAmount to INTEGER cents storage and modularize currency types
- Refactor MoneyAmount to store as INTEGER cents instead of TEXT decimals
- Move CurrencyType to separate currency_type.rs module
- Rename money.rs to money_amount.rs for clarity
- Update database schema to use INTEGER for all monetary columns
- Remove complex CAST AS REAL workarounds from database queries
- Add comprehensive test coverage for cent-based arithmetic and storage
- Enable STRICT mode and foreign key constraints in SQLite
- Add rstest dependency for parameterized testing

Benefits:
- Faster INTEGER-based comparisons vs TEXT casting
- Exact financial precision without floating-point errors
- Simpler, cleaner SQL queries
- Better performance for auction bid operations
2025-08-27 23:19:13 +00:00

2.4 KiB

id, title, status, assignee, created_date, updated_date, labels, dependencies
id title status assignee created_date updated_date labels dependencies
task-003 Create core database models and structs Done
@assistant
2025-08-27 18:31 2025-08-27 20:20

Description

Define Rust structs and enums that represent the database schema entities. This includes User, Auction, Bid, ProxyBid, AuctionMedia, and UserSettings models with proper SQLx derive macros.

Acceptance Criteria

  • #1 User struct with all fields from users table is defined
  • #2 Auction struct with AuctionType enum is defined
  • #3 Bid and ProxyBid structs are defined with proper relationships
  • #4 AuctionMedia and UserSettings structs are defined
  • #5 All models have proper SQLx derive macros (FromRow, Type, etc.)
  • #6 Rust Decimal is used for monetary fields
  • #7 Chrono DateTime is used for timestamp fields

Implementation Plan

  1. Create src/db module structure with models.rs
  2. Define ListingType enum with SQLx derive
  3. Create User struct matching users table
  4. Create Listing struct matching listings table
  5. Create ProxyBid, Bid, ListingMedia, UserSettings structs
  6. Add proper SQLx derives and field mappings
  7. Integrate models with main.rs

Implementation Notes

Successfully implemented comprehensive database model layer with all required structs and proper SQLx integration. Created User, Listing, ProxyBid, Bid, ListingMedia, and UserSettings models with correct field mappings. Used MoneyAmount (f64) type for SQLite compatibility. Added UserRepository with CRUD operations and user management functions. Created helper structs for insertions (NewUser, NewListing, etc.). All models compile and work with database schema. Added debug testing functionality to verify schema compatibility.

Successfully implemented comprehensive database models including:

  • Core models (User, Listing, Bid, ProxyBid, ListingMedia, UserSettings) with SQLx integration
  • MoneyAmount newtype with Decimal precision using NUMERIC (TEXT) storage in SQLite
  • CurrencyType enum with USD support using TEXT storage
  • Complete SQLx Type/Encode/Decode implementations for all custom types
  • Refactored money types to dedicated src/db/money.rs module for better organization
  • Added comprehensive unit tests covering all money operations and model functionality
  • All 10 unit tests passing successfully, including database integration tests
  • Models are production-ready with exact decimal precision for financial data