Skip to content

feat: Add AnalyticsDaily, AuditLog, soft-delete & timestamps to DB models#1070

Merged
Akanimoh12 merged 4 commits into
Akanimoh12:test-implement-dripsfrom
jayteemoney:feat/db-models-analytics-audit-timestamps
Jun 27, 2026
Merged

feat: Add AnalyticsDaily, AuditLog, soft-delete & timestamps to DB models#1070
Akanimoh12 merged 4 commits into
Akanimoh12:test-implement-dripsfrom
jayteemoney:feat/db-models-analytics-audit-timestamps

Conversation

@jayteemoney

@jayteemoney jayteemoney commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds the database models and conventions for four data-model issues, all in backend/prisma/schema.prisma with matching Prisma migrations. Targets test-implement-drips. The branch is rebased on the latest test-implement-drips and is purely additive (60 insertions, 0 deletions to the schema), so it merges without conflicts.

Closes #823
Closes #824
Closes #825
Closes #826

Changes

Issue Change
#823 AnalyticsDaily model — pre-aggregated daily metrics (date unique, totalTips, totalVolume, newUsers, activeUsers).
#824 AuditLog model — append-only admin/privileged action trail (actor, action, target, metadata, createdAt), indexed by actor/action/createdAt.
#825 Soft-delete convention — nullable deletedAt on user-facing resource models.
#826 createdAt @default(now()) + updatedAt @updatedAt on 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_daily
  • 20260626130100_add_audit_log
  • 20260626130200_add_soft_delete
  • 20260626130300_add_timestamps

Notes for the reviewer

  • Soft-delete scope (DB: Add soft-delete (deletedAt) convention #825): deletedAt was 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 no Profile/Resource models referenced in the issue, so the convention was applied to the equivalent models that actually exist.
  • Timestamps scope (DB: Add createdAt/updatedAt to all models #826): timestamps were added to every model lacking them, including the EventLog model recently merged into the base branch. New NOT NULL updatedAt columns are added with DEFAULT CURRENT_TIMESTAMP to backfill existing rows, then the default is dropped so the database matches the schema's bare @updatedAt with no drift. createdAt keeps its default (@default(now())).

Verification

  • prisma validate
  • prisma generate
  • Composite prisma migrate diff (base → final schema) matches the union of the four migrations.
  • A live migrate dev apply was not run (no Docker/Postgres in the working environment); reviewers can confirm with npm install && docker compose up -d && npx prisma migrate dev.

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.
@jayteemoney jayteemoney force-pushed the feat/db-models-analytics-audit-timestamps branch from 2916096 to 5e8d1a8 Compare June 26, 2026 14:55
@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@Akanimoh12 Akanimoh12 merged commit 339bbf7 into Akanimoh12:test-implement-drips Jun 27, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants