Problem
In src/database/schema.ts lines 32-34, the updatedAt column defaults to now() at creation but is only updated explicitly in user.service.ts line 59. When credits are updated (src/modules/rewards/reward.service.ts line 176), updatedAt is NOT updated.
Any system that relies on updatedAt to detect "last user activity" will be stale after reward claims.
Impact
updatedAt does not reflect actual last activity
- External systems relying on this field get stale data
- Inconsistent user activity tracking
Fix
Add a PostgreSQL trigger to auto-update updatedAt:
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ language 'plpgsql';
CREATE TRIGGER update_users_updated_at
BEFORE UPDATE ON users
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
Scope
- Create migration with trigger
- Update
src/database/schema.ts to document trigger
Acceptance Criteria
updatedAt is automatically updated on any user row change
- Credit updates reflect in
updatedAt
- Existing tests pass
Technical Context
src/database/schema.ts:32-34 -- updatedAt definition
src/modules/rewards/reward.service.ts:176 -- credit update
Problem
In
src/database/schema.tslines 32-34, theupdatedAtcolumn defaults tonow()at creation but is only updated explicitly inuser.service.tsline 59. When credits are updated (src/modules/rewards/reward.service.tsline 176),updatedAtis NOT updated.Any system that relies on
updatedAtto detect "last user activity" will be stale after reward claims.Impact
updatedAtdoes not reflect actual last activityFix
Add a PostgreSQL trigger to auto-update
updatedAt:Scope
src/database/schema.tsto document triggerAcceptance Criteria
updatedAtis automatically updated on any user row changeupdatedAtTechnical Context
src/database/schema.ts:32-34-- updatedAt definitionsrc/modules/rewards/reward.service.ts:176-- credit update