Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Nov 19, 2025

Summary by CodeRabbit

  • Refactor

    • Removed deprecated calculated stats fields from program enrollment data model
    • Removed amount field from reward data model as part of schema cleanup
  • Chores

    • Updated migration scripts with improved documentation comments

@vercel
Copy link
Contributor

vercel bot commented Nov 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Nov 19, 2025 5:11am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

The PR removes deprecated schema fields and updates TypeScript directives in migration scripts. Specifically: two calculated stats fields (leadConversionRate, conversionRate) are deleted from the ProgramEnrollment model, the amount field is removed from the Reward model, and TypeScript nocheck comments are added/updated in migration scripts.

Changes

Cohort / File(s) Change Summary
Migration script TypeScript directives
apps/web/scripts/migrations/migrate-reward-amounts.ts, apps/web/scripts/migrations/migrate-rewards-remainder.ts
Added or updated top-of-file TypeScript nocheck directives; minor comment enhancement on the second file for clarity. No functional behavior changes.
Schema field removals
packages/prisma/schema/program.prisma
Removed two deprecated calculated stats fields from ProgramEnrollment model: leadConversionRate and conversionRate.
Reward schema field removal
packages/prisma/schema/reward.prisma
Removed the amount field (with @default(0) directive and TODO comment) from the Reward model.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Focus areas:
    • Verify that the removed Reward.amount field is not referenced in API handlers, services, or database queries
    • Confirm that leadConversionRate and conversionRate fields are no longer accessed in code or reports
    • Check migration scripts to ensure they properly handle the removal of these fields

Possibly related PRs

Poem

🐰 Deprecated fields fade away,
Schema cleanup saves the day,
Nocheck comments guide the path,
Reward amount feels TypeScript's wrath,
Cleaner schemas hoppily stay! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Remove old columns' accurately describes the main objective of the changeset, which involves removing deprecated fields across multiple schema files and migration scripts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch remove-columns

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
Contributor

@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: 0

🧹 Nitpick comments (1)
apps/web/scripts/migrations/migrate-reward-amounts.ts (1)

35-90: Consider adding error handling for robust migration execution.

The script lacks try-catch blocks around the update operations (lines 78–87). If any reward update fails mid-batch, the script halts and the database is left in a partially migrated state, requiring manual re-run and potential duplicate-processing issues.

Consider wrapping the update in a try-catch block to log errors and optionally continue with the next reward, or wrap the entire loop in error handling to make re-runs safer.

  for (const reward of rewards) {
    try {
      const amount = reward.amount ?? 0;
      // ... migration logic ...
      await prisma.reward.update({
        where: { id: reward.id },
        data: {
          amountInCents,
          amountInPercentage,
          modifiers: updatedModifiers ?? Prisma.DbNull,
        },
      });
      totalMigrated++;
    } catch (error) {
      console.error(`Failed to migrate reward ${reward.id}:`, error);
      // Decide: throw to halt, or continue to next reward
      throw error;
    }
  }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30f55f5 and 98d5285.

📒 Files selected for processing (4)
  • apps/web/scripts/migrations/migrate-reward-amounts.ts (1 hunks)
  • apps/web/scripts/migrations/migrate-rewards-remainder.ts (1 hunks)
  • packages/prisma/schema/program.prisma (0 hunks)
  • packages/prisma/schema/reward.prisma (0 hunks)
💤 Files with no reviewable changes (2)
  • packages/prisma/schema/reward.prisma
  • packages/prisma/schema/program.prisma
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: TWilson023
Repo: dubinc/dub PR: 2935
File: packages/prisma/schema/workspace.prisma:21-36
Timestamp: 2025-10-06T15:48:45.956Z
Learning: In the Dub repository (dubinc/dub), Prisma schema changes are not managed with separate migration files. Do not flag missing Prisma migration files when schema changes are made to files like `packages/prisma/schema/workspace.prisma` or other schema files.
📚 Learning: 2025-10-06T15:48:45.956Z
Learnt from: TWilson023
Repo: dubinc/dub PR: 2935
File: packages/prisma/schema/workspace.prisma:21-36
Timestamp: 2025-10-06T15:48:45.956Z
Learning: In the Dub repository (dubinc/dub), Prisma schema changes are not managed with separate migration files. Do not flag missing Prisma migration files when schema changes are made to files like `packages/prisma/schema/workspace.prisma` or other schema files.

Applied to files:

  • apps/web/scripts/migrations/migrate-rewards-remainder.ts
📚 Learning: 2025-09-24T16:13:00.387Z
Learnt from: TWilson023
Repo: dubinc/dub PR: 2872
File: packages/prisma/schema/partner.prisma:151-153
Timestamp: 2025-09-24T16:13:00.387Z
Learning: In the Dub codebase, Prisma schemas use single-column indexes without brackets (e.g., `@index(partnerId)`) and multi-column indexes with brackets (e.g., `@index([programId, partnerId])`). This syntax pattern is consistently used throughout their schema files and works correctly with their Prisma version.

Applied to files:

  • apps/web/scripts/migrations/migrate-rewards-remainder.ts
📚 Learning: 2025-09-12T17:31:10.548Z
Learnt from: devkiran
Repo: dubinc/dub PR: 2833
File: apps/web/lib/actions/partners/approve-bounty-submission.ts:53-61
Timestamp: 2025-09-12T17:31:10.548Z
Learning: In approve-bounty-submission.ts, the logic `bounty.rewardAmount ?? rewardAmount` is intentional. Bounties with preset reward amounts should use those fixed amounts, and the rewardAmount override parameter is only used when bounty.rewardAmount is null/undefined (for custom reward bounties). This follows the design pattern where bounties are either "flat rate" (fixed amount) or "custom" (variable amount set during approval).

Applied to files:

  • apps/web/scripts/migrations/migrate-reward-amounts.ts
📚 Learning: 2025-07-30T15:25:13.936Z
Learnt from: TWilson023
Repo: dubinc/dub PR: 2673
File: apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx:56-66
Timestamp: 2025-07-30T15:25:13.936Z
Learning: In apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx, the form schema uses partial condition objects to allow users to add empty/unconfigured condition fields without type errors, while submission validation uses strict schemas to ensure data integrity. This two-stage validation pattern improves UX by allowing progressive completion of complex forms.

Applied to files:

  • apps/web/scripts/migrations/migrate-reward-amounts.ts
📚 Learning: 2025-07-30T15:29:54.131Z
Learnt from: TWilson023
Repo: dubinc/dub PR: 2673
File: apps/web/ui/partners/rewards/rewards-logic.tsx:268-275
Timestamp: 2025-07-30T15:29:54.131Z
Learning: In apps/web/ui/partners/rewards/rewards-logic.tsx, when setting the entity field in a reward condition, dependent fields (attribute, operator, value) should be reset rather than preserved because different entities (customer vs sale) have different available attributes. Maintaining existing fields when the entity changes would create invalid state combinations and confusing UX.

Applied to files:

  • apps/web/scripts/migrations/migrate-reward-amounts.ts
📚 Learning: 2025-08-14T05:17:51.825Z
Learnt from: devkiran
Repo: dubinc/dub PR: 2735
File: apps/web/lib/actions/partners/delete-reward.ts:33-41
Timestamp: 2025-08-14T05:17:51.825Z
Learning: In the partner groups system, a rewardId can only belong to one group, establishing a one-to-one relationship between rewards and groups. This means using Prisma's `update` method (rather than `updateMany`) is appropriate when updating groups by rewardId.

Applied to files:

  • apps/web/scripts/migrations/migrate-reward-amounts.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (4)
apps/web/scripts/migrations/migrate-reward-amounts.ts (3)

1-6: Verify deployment order: migration script must run before schema changes.

The script queries and selects the amount field (line 21), which is being removed from the Reward schema. Ensure this migration script runs against the database before the Prisma schema is updated to remove the amount column.


36-45: Verify that defaulting null amounts to 0 is intentional.

Line 36 defaults reward.amount ?? 0, so rewards with null or undefined amounts will be migrated as zero-valued rewards. Ensure this behavior matches business intent—otherwise, consider throwing an error to flag unexpected missing amounts.


47-72: Type migration and modifier fallback logic is sound.

The script correctly maps old amount to new fields based on reward type, and applies sensible fallback logic: if a modifier lacks a type, it inherits the parent reward's type (line 64). The Prisma.DbNull usage (line 85) is correct for setting modifiers to NULL when undefined.

apps/web/scripts/migrations/migrate-rewards-remainder.ts (1)

1-1: Documentation update is clear and consistent.

The @ts-nocheck comment now accurately describes the purpose—that the script contains old schema code. This aligns with the pattern established in migrate-reward-amounts.ts and improves maintainability for future readers.

@steven-tey steven-tey merged commit 5dedf6d into main Nov 19, 2025
8 of 9 checks passed
@steven-tey steven-tey deleted the remove-columns branch November 19, 2025 05:16
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.

2 participants