track daily login streak for players#140
Conversation
WalkthroughIntroduces player_join_events table, adjusts player_bans and players defaults/constraints, adds players.daily_login_streak column, and wires daily login streak computation into player document handling via a new helper. Updates schema, queries, Zod schema, and migration snapshots/journal accordingly. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Player
participant API as Backend API
participant DB as Database
Player->>API: Join server (uuid, ip)
API->>DB: INSERT player_join_events (player_uuid, ip_address, timestamp)
DB-->>API: Insert OK
API->>DB: SELECT players (lastJoinedDate, daily_login_streak)
DB-->>API: Player row
API->>API: calculateDailyLoginStreak(prevStreak, lastJoinedDate, now)
API->>DB: UPDATE players SET daily_login_streak = newStreak, last_joined = now
DB-->>API: Update OK
API-->>Player: Return PlayerDocument (includes dailyLoginStreak)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
apps/backend/src/db/migrations/0002_flippant_penance.sql(1 hunks)apps/backend/src/db/migrations/0003_wealthy_nehzno.sql(1 hunks)apps/backend/src/db/migrations/meta/0002_snapshot.json(1 hunks)apps/backend/src/db/migrations/meta/0003_snapshot.json(1 hunks)apps/backend/src/db/migrations/meta/_journal.json(1 hunks)apps/backend/src/db/queries/player-documents.ts(5 hunks)apps/backend/src/db/schema/players.ts(2 hunks)apps/backend/src/helpers/daily-login-streak.ts(1 hunks)apps/backend/src/schemas/player-document.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/backend/src/db/queries/player-documents.ts (1)
apps/backend/src/helpers/daily-login-streak.ts (1)
calculateDailyLoginStreak(1-26)
🔇 Additional comments (1)
apps/backend/src/db/migrations/0002_flippant_penance.sql (1)
10-13: Confirm no NULLplayer_uuidentries inplayer_bansbefore applying NOT NULL constraintEnsure there are zero rows where
player_uuidis NULL, or the migration will fail. Manually run on your live database:SELECT COUNT(*) AS null_player_uuid FROM player_bans WHERE player_uuid IS NULL;Verify the result is 0 before deploying this migration.
Fixes #135
Summary by CodeRabbit
New Features
Chores