Resolve "Age update automatically every year and DOB(Year mandatory) should be taken"
Merge Request
Overview
This MR updates the user data model by replacing the age field with date_of_birth (DOB).
The goal is to eliminate storing derived data (age) and instead store the source of truth (DOB). Age will now be dynamically calculated when required.
What does this MR do and why?
Previously, the system stored age directly in the database. This approach caused:
- Data inconsistency over time (age becomes outdated)
- Redundant data storage
- Manual updates required to maintain accuracy
Solution
- Removed
agecolumn from the database - Introduced
date_of_birthcolumn - Updated backend logic to calculate age dynamically from DOB
Benefits
- Ensures accurate and up-to-date age calculation
- Follows best practice (store source, not derived data)
- Reduces data inconsistency issues
Changes Made
Database
- Removed:
agecolumn fromuserstable - Added:
date_of_birth(DATE type)
Backend
- Updated User model/schema
- Added utility function to calculate age from DOB
- Updated API responses to return computed
age
API Changes
-
Request:
-
date_of_birthadded -
ageremoved
-
-
Response:
-
ageis dynamically calculated and returned
-
Files Modified
- models/user.py
- schemas/user_schema.py
- services/user_service.py
- migrations/xxxx_add_dob_remove_age.py
Technical Details
Root Cause
Storing age directly leads to stale data since it changes over time.
Fix
- Store
date_of_birthinstead - Calculate age dynamically using current date
Example Logic
from datetime import date
def calculate_age(dob: date) -> int:
today = date.today()
return today.year - dob.year - (
(today.month, today.day) < (dob.month, dob.day)
)
Type of Change
-
✨ New feature -
📝 Documentation update -
🧪 Test update -
🔧 Configuration change
Related Issues / References
- Closes #56 (closed)
Screenshots
How to Validate Locally
- Run migrations:
alembic upgrade head
- Create a new user:
- Provide
date_of_birth - Ensure
ageis NOT accepted
- Fetch user details:
- Verify
ageis calculated correctly
Expected Behavior
| Before | After |
|---|---|
| Age stored in DB | DOB stored in DB |
| Age static | Age dynamic |
| Manual updates needed | Auto-calculated |
Testing Done
-
API endpoint tests passing
Test Cases Covered
| Scenario | Expected Result | Status |
|---|---|---|
| Create user with DOB | User created successfully | |
| Fetch user | Age calculated correctly | |
| Missing DOB | Validation error |
Code Quality Checklist
Code Standards
-
Code follows project conventions -
No unused code -
Type hints added
API Design
-
Proper validation for DOB -
Correct HTTP responses -
API docs updated
Database & Migrations
-
Migration created -
Downgrade supported -
Schema updated correctly
Security
-
No sensitive data exposed -
Input validation implemented
Documentation
-
API docs updated -
.env.exampleunchanged
Known Limitations / Technical Debt
- Existing users with
ageneed migration handling (default DOB or manual update)
Additional Notes
- This change may impact frontend forms — ensure DOB field is used instead of age input
MR Acceptance Checklist
Quality & Correctness
-
Works as expected -
No regressions
Maintainability
-
Clean and readable code -
Follows best practices
Edited by POORNA CHANDRA SAI TEJA KUMPATLA


