Skip to content

track daily login streak for players#140

Merged
BetrixDev merged 2 commits intoreimaginedfrom
feature/daily-login-streak
Sep 28, 2025
Merged

track daily login streak for players#140
BetrixDev merged 2 commits intoreimaginedfrom
feature/daily-login-streak

Conversation

@BetrixDev
Copy link
Owner

@BetrixDev BetrixDev commented Sep 28, 2025

Fixes #135

Summary by CodeRabbit

  • New Features

    • Daily login streak tracking for players, automatically calculated on join and stored on profiles.
    • Player join events now recorded (timestamp and IP) to enhance account history.
  • Chores

    • Database schema updated: streak field, join-events table, defaults adjusted, and stronger foreign-key rules for safer cleanup.
    • Migration snapshots and journal updated to reflect the new schema.

@coderabbitai
Copy link

coderabbitai bot commented Sep 28, 2025

Walkthrough

Introduces 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

Cohort / File(s) Summary
DB Migrations (SQL)
apps/backend/src/db/migrations/0002_flippant_penance.sql, apps/backend/src/db/migrations/0003_wealthy_nehzno.sql
Adds player_join_events table with FK to players(uuid) (ON DELETE CASCADE); drops and re-adds FK on player_bans.player_uuid and makes it NOT NULL; sets players.stats default to '{}'::jsonb; adds players.daily_login_streak integer NOT NULL DEFAULT 0.
Migration Metadata & Journal
apps/backend/src/db/migrations/meta/0002_snapshot.json, apps/backend/src/db/migrations/meta/0003_snapshot.json, apps/backend/src/db/migrations/meta/_journal.json
Adds/updates migration snapshots reflecting new table/column/FK/index state and appends journal entries for migrations 0002/0003.
DB Schema (Drizzle)
apps/backend/src/db/schema/players.ts
Exposes dailyLoginStreak integer column with .default(0).notNull(); imports integer from pg-core.
Helper
apps/backend/src/helpers/daily-login-streak.ts
New calculateDailyLoginStreak(previousStreak, lastJoinDate, now) utility implementing day-based streak logic.
Schema (Zod)
apps/backend/src/schemas/player-document.ts
Adds nullable dailyLoginStreak to playerDocumentSchema; PlayerDocument type gains `dailyLoginStreak: number
Queries / Documents
apps/backend/src/db/queries/player-documents.ts
Reads, initializes, recalculates (on join) and persists dailyLoginStreak in PlayerDocument; imports helper.

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)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Poem

Thump-thump with a carrot grin,
I count the days the players win.
One hop more, the streak is bright,
Events logged by moonlit night.
Binky cheers — migrations done! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The migration 0002 script includes alterations to the player_bans foreign key constraints and changes the default of players.stats, neither of which are necessary for implementing daily login streak tracking per issue #135, indicating unrelated modifications beyond the scope of the linked feature. Please isolate or remove the player_bans foreign key modifications and the players.stats default change into a separate migration or PR, ensuring this pull request only contains changes related to daily login streak functionality.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "track daily login streak for players" accurately and concisely describes the main feature introduced by this pull request, namely the implementation of daily login streak tracking for player accounts, aligning with the linked issue’s objective.
Linked Issues Check ✅ Passed This pull request fulfills issue #135 by adding the daily_login_streak column to the players table via migration 0003, introducing the player_join_events table in migration 0002 to record login events, implementing the calculateDailyLoginStreak helper for computing streaks, and updating the query and schema layers to store and retrieve the streak value, thereby covering all coding-related requirements for tracking daily login streaks.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/daily-login-streak

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b1d1fd and 5d62b75.

📒 Files selected for processing (2)
  • apps/backend/src/db/migrations/0003_wealthy_nehzno.sql (1 hunks)
  • apps/backend/src/schemas/player-document.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/backend/src/schemas/player-document.ts
  • apps/backend/src/db/migrations/0003_wealthy_nehzno.sql

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 31c7129 and 6b1d1fd.

📒 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 NULL player_uuid entries in player_bans before applying NOT NULL constraint

Ensure there are zero rows where player_uuid is 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.

@BetrixDev BetrixDev merged commit 5f6677a into reimagined Sep 28, 2025
2 checks passed
@BetrixDev BetrixDev deleted the feature/daily-login-streak branch September 28, 2025 02:37
@coderabbitai coderabbitai bot mentioned this pull request Oct 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Track daily login streak for players on server

1 participant