Skip to content

updatedAt not auto-updated on credit changes -- no DB trigger #229

Description

@DeFiVC

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

  1. updatedAt is automatically updated on any user row change
  2. Credit updates reflect in updatedAt
  3. Existing tests pass

Technical Context

  • src/database/schema.ts:32-34 -- updatedAt definition
  • src/modules/rewards/reward.service.ts:176 -- credit update

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingmedium

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions