feat: Add AnalyticsDaily, AuditLog, soft-delete & timestamps to DB models#1070
Merged
Akanimoh12 merged 4 commits intoJun 27, 2026
Conversation
Add a pre-aggregated daily analytics table (one row per UTC day) holding totalTips, totalVolume, newUsers and activeUsers, with a unique date so a scheduled job can upsert per-day rows for dashboard trend reads.
Add an append-only AuditLog (actor, action, target, metadata, createdAt) so privileged/admin operations are recorded for accountability, indexed by actor, action and createdAt for querying.
Add a nullable deletedAt to the user-facing resource models (User, ApiKey, Notification, Goal, Subscription) so records can be logically deleted instead of hard-deleted; a non-null value marks the row as deleted. Immutable/on-chain and append-only models (Tip, Refund, EventLog, AuditLog, AnalyticsDaily) and infra tables are intentionally excluded.
Ensure every model carries createdAt @default(now()) and updatedAt @updatedat. Adds the missing timestamps to Tip, IndexerCursor, EventLog, Refund, Notification, XAccount, LeaderboardSnapshot, AuthChallenge, RefreshToken, AnalyticsDaily and AuditLog. The migration backfills new NOT NULL updatedAt columns with CURRENT_TIMESTAMP then drops the default so the database matches the schema (bare @updatedat) with no drift.
2916096 to
5e8d1a8
Compare
|
@jayteemoney Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
339bbf7
into
Akanimoh12:test-implement-drips
4 of 5 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the database models and conventions for four data-model issues, all in
backend/prisma/schema.prismawith matching Prisma migrations. Targetstest-implement-drips. The branch is rebased on the latesttest-implement-dripsand is purely additive (60 insertions, 0 deletions to the schema), so it merges without conflicts.Closes #823
Closes #824
Closes #825
Closes #826
Changes
AnalyticsDailymodel — pre-aggregated daily metrics (dateunique,totalTips,totalVolume,newUsers,activeUsers).AuditLogmodel — append-only admin/privileged action trail (actor,action,target,metadata,createdAt), indexed by actor/action/createdAt.deletedAton user-facing resource models.createdAt @default(now())+updatedAt @updatedAton every model.Migrations
Each migration was generated from the immediately preceding schema state, so they compose exactly to the final schema, and are timestamped after the base branch's latest migration (
20260626120000_add_indexes):20260626130000_add_analytics_daily20260626130100_add_audit_log20260626130200_add_soft_delete20260626130300_add_timestampsNotes for the reviewer
deletedAtwas added to the user-facing resource models —User,ApiKey,Notification,Goal,Subscription. Immutable / on-chain / append-only models (Tip,Refund,EventLog,AuditLog,AnalyticsDaily) and infra tables (AuthChallenge,RefreshToken,IndexerCursor,LeaderboardSnapshot,XAccount,WebhookDelivery) are intentionally excluded. The schema has noProfile/Resourcemodels referenced in the issue, so the convention was applied to the equivalent models that actually exist.EventLogmodel recently merged into the base branch. NewNOT NULL updatedAtcolumns are added withDEFAULT CURRENT_TIMESTAMPto backfill existing rows, then the default is dropped so the database matches the schema's bare@updatedAtwith no drift.createdAtkeeps its default (@default(now())).Verification
prisma validate✅prisma generate✅prisma migrate diff(base → final schema) matches the union of the four migrations.migrate devapply was not run (no Docker/Postgres in the working environment); reviewers can confirm withnpm install && docker compose up -d && npx prisma migrate dev.