Skip to content

refactor: update badge definitions and consolidate alembic migration heads

Suma Pullaiahgari requested to merge ehrs-badges-update into develop

Merge Request

Overview

This MR refactors the badge system by renaming "Century Contributor" to "Active Volunteer" and removing the rarely-used "Elite Volunteer" badge, while also adding type hints and updating associated files.

What does this MR do and why?

This refactor improves the badge naming to be more descriptive and removes a badge milestone that is rarely achieved. The changes include:

  • Rename: "Century Contributor" (10 visits) → "Active Volunteer" - better reflects the milestone
  • Remove: "Elite Volunteer" (36 visits) - rarely earned, clutters the badge system
  • Type hints: Added proper type annotations to Badge model columns
  • Migration: Created Alembic migration to update production database

Changes Made

Files Modified

  1. alembic/versions/20260428_badge_updates.py (new file)

    • Renames "Century Contributor" to "Active Volunteer"
    • Deletes "Elite Volunteer" badge definition
  2. app/models/badge.py

    • Added type hints to criteria_type and criteria_value columns
  3. app/services/badge_service.py

    • Updated BADGE_DEFINITIONS to reflect new badge names/definitions
    • Minor code formatting improvements
  4. scripts/seed_database.py

    • Updated seed_badges() function with new badge definitions

Type of Change

  • 🐛 Bug fix
  • New feature
  • 💥 Breaking change
  • 📝 Documentation update
  • ️ Refactor
  • Performance improvement
  • 🧪 Test update
  • 🔧 Configuration change
  • 🚨 Security fix
  • 🗑️ Deprecation

Related Issues / References

How to Validate Locally

  1. Run database seed with clear:

    uv run python -m scripts.seed_database --clear
  2. Verify badge definitions:

    • Check database: SELECT name, criteria_value FROM badges ORDER BY criteria_value;
    • Should have 8 badges (not 9)
    • "Active Volunteer" should exist
    • "Elite Volunteer" should NOT exist
  3. Test badge evaluation:

    • Create a volunteer with multiple camp visits
    • Verify badges are awarded correctly
    • Verify badge progress shows correct counts

Testing Done

  • Local testing with fresh database seed
  • Verified badge definitions in database
  • Code passes linting

Test Commands Run:

# Run lint
ruff check .
ruff format . --check

# Type check
mypy app/

Code Quality Checklist

Code Standards

  • Code follows project conventions
  • No debug statements or commented-out code
  • No unused imports, variables, or functions
  • Type hints properly defined
  • Ruff checks pass

Python & FastAPI Best Practices

  • Functions follow single-responsibility principle
  • Async/await used correctly
  • Dependency injection used appropriately

API Design

  • RESTful conventions followed
  • Input validation implemented

Database & Migrations

  • Database migrations created
  • Migrations are reversible
  • No raw SQL queries (using ORM)

Security

  • No sensitive data logged
  • SQL injection prevention verified

Error Handling

  • Errors are caught and handled gracefully
  • Errors are logged appropriately

Documentation

  • README.md updated
  • API documentation updated

Known Limitations / Technical Debt

  • The alembic migration cannot restore deleted user_badges records for "Elite Volunteer" if users had earned it before this migration runs.

Additional Notes

  • The badge count changed from 9 to 8
  • This is purely a refactor - no functional behavior change for users
  • Migration consolidates two previous migration heads

MR Acceptance Checklist

Quality & Correctness

  • Code solves the stated problem
  • No bugs introduced

Maintainability

  • Code is readable and well-organized

Acceptance Review

  • Reviewed by at least 1 teammate
  • Reviewed by product owner

Merge request reports

Loading