Harmonize database field names: standardize 'size' vs 'size_bytes' #159

Open
opened 2025-10-14 22:06:28 +00:00 by tegwick · 0 comments
Owner

Problem

The asset management system uses inconsistent field names for asset size across different components:

  • Registry stores: 'size'
  • Database schema expects: 'size_bytes'
  • Asset model uses: 'size_bytes'

This creates unnecessary conversion overhead and potential bugs.

Root Cause

The registry was implemented before the database schema was finalized, leading to different naming conventions.

Evidence

  • markitect/assets/registry.py:178: asset_info['size'] = stat.st_size
  • markitect/assets/database.py schema uses: size_bytes BIGINT NOT NULL
  • markitect/assets/models.py:84: size_bytes=data.get('size_bytes', data.get('size', 0))

Impact

  • Data conversion required in Asset.from_dict() method
  • Potential confusion for developers
  • Risk of bugs when field names are mixed up
  • Reduced performance due to field mapping

Proposed Solution

Option A (Recommended): Standardize on 'size_bytes' everywhere

  • Update registry to use 'size_bytes'
  • Remove conversion logic from Asset model
  • More explicit about units (bytes)

Option B: Standardize on 'size' everywhere

  • Update database schema to use 'size'
  • Less explicit about units

Files Affected

  • markitect/assets/registry.py - Asset registration
  • markitect/assets/models.py - Conversion logic
  • markitect/assets/database.py - Schema definition

Priority

Low - System works but creates technical debt

## Problem The asset management system uses inconsistent field names for asset size across different components: - Registry stores: 'size' - Database schema expects: 'size_bytes' - Asset model uses: 'size_bytes' This creates unnecessary conversion overhead and potential bugs. ## Root Cause The registry was implemented before the database schema was finalized, leading to different naming conventions. ## Evidence - markitect/assets/registry.py:178: asset_info['size'] = stat.st_size - markitect/assets/database.py schema uses: size_bytes BIGINT NOT NULL - markitect/assets/models.py:84: size_bytes=data.get('size_bytes', data.get('size', 0)) ## Impact - Data conversion required in Asset.from_dict() method - Potential confusion for developers - Risk of bugs when field names are mixed up - Reduced performance due to field mapping ## Proposed Solution **Option A (Recommended)**: Standardize on 'size_bytes' everywhere - Update registry to use 'size_bytes' - Remove conversion logic from Asset model - More explicit about units (bytes) **Option B**: Standardize on 'size' everywhere - Update database schema to use 'size' - Less explicit about units ## Files Affected - markitect/assets/registry.py - Asset registration - markitect/assets/models.py - Conversion logic - markitect/assets/database.py - Schema definition ## Priority Low - System works but creates technical debt
tegwick added this to the Images And File Attachments project 2025-10-14 22:21:06 +00:00
Sign in to join this conversation.