Skip to content

fix(db): use partialFilterExpression for stripeCustomerId unique index - #125

Merged
rekabytes merged 1 commit into
mainfrom
dev
Apr 8, 2026
Merged

fix(db): use partialFilterExpression for stripeCustomerId unique index#125
rekabytes merged 1 commit into
mainfrom
dev

Conversation

@rekabytes

Copy link
Copy Markdown
Owner

The original migration used { sparse: true, unique: true } which still fails with E11000 when multiple users have stripeCustomerId: null (sparse only skips missing fields, not explicit nulls).

  • Fix 000001 in place: replace sparse with partialFilterExpression so only real string Stripe IDs are included in the unique index
  • Add 000004 safety net: drops and recreates the index properly for environments where 000001 partially applied

📝 Description

Brief description of what this PR does.

🔗 Related Issue

Fixes #(issue number)

🏷️ Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🧹 Code refactoring (no functional changes)
  • 🧪 Test update (adding or updating tests)

✅ Checklist

  • I have read the Contributing Guidelines
  • My branch is created from dev (not main)
  • I have run pnpm lint:fix
  • I have run pnpm typecheck
  • I have tested my changes locally
  • My code follows the project's coding standards
  • I have updated documentation (if applicable)

📸 Screenshots (if applicable)

Add screenshots to help explain your changes.

🧪 How to Test

Steps to test this PR:

  1. ...
  2. ...
  3. ...

📝 Additional Notes

Any additional information reviewers should know.

The original migration used { sparse: true, unique: true } which still
fails with E11000 when multiple users have stripeCustomerId: null
(sparse only skips missing fields, not explicit nulls).

- Fix 000001 in place: replace sparse with partialFilterExpression
  so only real string Stripe IDs are included in the unique index
- Add 000004 safety net: drops and recreates the index properly
  for environments where 000001 partially applied
@vercel

vercel Bot commented Apr 8, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
kal-admin Ready Ready Preview, Comment Apr 8, 2026 3:57am
kal-frontend Building Building Preview, Comment Apr 8, 2026 3:57am

@rekabytes
rekabytes merged commit 90365c2 into main Apr 8, 2026
5 of 6 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

Development

Successfully merging this pull request may close these issues.

1 participant