Skip to content

Comments

Fix modreport dates and recover corrupted timestamps#284

Merged
vcarl merged 1 commit intomainfrom
fix-modreport-dates-and-recover-timestamps
Feb 20, 2026
Merged

Fix modreport dates and recover corrupted timestamps#284
vcarl merged 1 commit intomainfrom
fix-modreport-dates-and-recover-timestamps

Conversation

@vcarl
Copy link
Member

@vcarl vcarl commented Feb 20, 2026

Summary

Fixes critical date bugs in /modreport and recovers timestamps corrupted by migration:

  • First/last reported dates now show correctly (not "today")
  • Recovered historical timestamps from Discord snowflake IDs
  • Improved formatting with bullet lists
  • Added detailed staff reporter breakdown

Root Cause

The 20260218120000_fix_created_at_defaults migration was destructive:

  1. Schema bug: default 'CURRENT_TIMESTAMP' stored as literal string instead of function
  2. All old reports had created_at = 'CURRENT_TIMESTAMP' (string)
  3. Migration set all to datetime('now'), destroying historical data
  4. Result: "first reported" showed migration date instead of actual first report

Solution

Data Recovery

  • Extract timestamps from Discord snowflake IDs: ((id >> 22) + 1420070400000) / 1000
  • Updated migration to recover from log_message_id, thread_id
  • Added new migration to recover already-corrupted production data
  • Only updates rows in corruption window (Feb 18-21, 2026)

Code Improvements

  • Changed MIN/MAX to explicit ORDER BY + LIMIT for reliability
  • Changed inline (·) to newline formatting for channels/reasons
  • Added "Reported By" field with staff breakdown

Test Plan

  • All tests pass
  • Types check
  • Linting passes
  • Validated on production backup - 2,108 timestamps recovered
  • Deploy and verify /modreport shows correct historical dates

🤖 Generated with Claude Code

Fixes three issues with the /modreport command:

1. **Date queries**: Changed from MIN/MAX aggregates to explicit ORDER BY +
   LIMIT queries for more reliable first/last report dates

2. **Formatting**: Changed channel and reason breakdowns from inline (·-separated)
   to newline-separated lists for better readability

3. **Staff breakdown**: Added detailed "Reported By" field showing which staff
   members reported the user and how many times

**Migration fixes:**

- Updated 20260218120000_fix_created_at_defaults.ts to recover timestamps from
  Discord snowflake IDs instead of destroying data with datetime('now')

- Added 20260220130000_recover_dates_from_snowflakes.ts to recover timestamps
  already corrupted in production by the previous destructive migration

Discord snowflake IDs encode creation time in the first 42 bits, allowing us
to recover original timestamps: ((id >> 22) + 1420070400000) / 1000

This fixes the bug where "first reported" was showing today's date instead of
the actual first report date due to migration-time data corruption.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@vcarl vcarl merged commit 04eb40e into main Feb 20, 2026
5 checks passed
@vcarl vcarl deleted the fix-modreport-dates-and-recover-timestamps branch February 20, 2026 21:25
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.

1 participant