Moving from a strict date column to distinct month, day, and year fields is a highly effective way to handle partial user data. It allows users to celebrate their birthdays without forcing them to disclose their exact age.
1. Database Overhaul
We are updating the PostgreSQL people table to support the new format.
- New Columns: We will add
birth_month,birth_day, andbirth_yearas small integers. - Data Cleanup: The legacy
birthdatecolumn will be entirely deleted. Existing data will not be migrated. - Data Integrity Rules: The database will strictly enforce logic to prevent invalid entries:
- Month and day must always exist together.
- A year can only be saved if a month and day are also provided.
- Months are restricted to 1 through 12.
- Days are restricted to 1 through 31.
2. Application Data Types (Go)
The core structure of a "Person" in the backend codebase (types/types.go) will be updated. The old Birthdate time object will be removed and replaced with three independent integer fields: BirthMonth, BirthDay, and BirthYear.
3. SQL Query Updates
Every backend function that reads or writes person data (UpdatePerson, GetPerson, CreatePerson) must be rewired.
- We will replace the single
birthdatereference with the three new columns in all SELECT, INSERT, and UPDATE operations. - Because we are expanding one column into three, the sequential parameter tracking numbers in the raw SQL queries (e.g.,
$6,$7) will shift and require careful recalculation.
4. API Validation Logic
When the frontend sends a request to add or edit a person, the backend will no longer try to parse a date string. Instead, it will look for the new integer fields and run them through a strict validation gauntlet before touching the database:
- If a month is provided without a day (or vice versa), the server will reject the request.
- If a year is provided without a month and day, the server will reject the request.
- If the numbers fall outside standard calendar ranges, the server returns a "400 Bad Request" error.
5. The New API Contract
The frontend will communicate with the backend using a much simpler JSON structure.
| Scenario | Payload Example |
| Complete Birthday | {"birth_month": 3, "birth_day": 15, "birth_year": 1990} |
| Partial (No Year) | {"birth_month": 3, "birth_day": 15} |
| No Birthday | {} |