Add scripts - #7
Conversation
add scripts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Missing same-user guard causes confusing transaction failure
- Added an early
wrongUser.id === correctUser.idcheck that aborts with a clear message before any transaction logic runs.
- Added an early
Or push these changes by commenting:
@cursor push eeb3b308bf
Preview (eeb3b308bf)
diff --git a/scripts/fix-poll-user.ts b/scripts/fix-poll-user.ts
--- a/scripts/fix-poll-user.ts
+++ b/scripts/fix-poll-user.ts
@@ -42,6 +42,13 @@
return;
}
+ if (wrongUser.id === correctUser.id) {
+ console.error(
+ `Both emails resolve to the same user (${wrongUser.id}). Use two different users to run this script.`,
+ );
+ return;
+ }
+
console.log("\n--- Wrong email user (has the poll) ---");
console.log(` ID: ${wrongUser.id}`);
console.log(` Email: ${wrongUser.email}`);Comment @cursor review or bugbot run to trigger another review on this PR
| if (!correctUser) { | ||
| console.error(`No user found with email: ${correctEmail}`); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Missing same-user guard causes confusing transaction failure
Low Severity
If the operator enters the same email for both wrongEmail and correctEmail, both user objects resolve to the same user. The transaction's step 1 deletes the user's own campaigns (treated as "accidental"), and step 2 then attempts to update those already-deleted campaigns, causing a confusing Prisma "Record not found" error. If the user has polls, the safety check fires with a misleading "aborting to avoid data loss" message. In both cases the transaction rolls back safely, but the root cause (identical emails) is not surfaced. A simple wrongUser.id === correctUser.id early return after fetching both users would prevent this.



Add scripts:
Note
Medium Risk
Adds operational scripts that perform destructive/irreversible Prisma mutations (deleting campaigns and users) and can enqueue production SQS messages; misuse could cause data loss or unintended job execution, though changes are isolated to
scripts/.Overview
Adds
scripts/fix-poll-user.ts, an interactive Prisma transaction script to move campaigns/elected offices (and thus polls) from a wrong-email user to the correct user, optionally deleting the correct user’s accidental campaigns and finally deleting the wrong user.Adds
scripts/resend-poll-creation.tsto re-enqueue apollCreationSQS message for a specific poll after prompting for confirmation.Updates
scripts/poll-problem.tsto also report the count ofpollIndividualMessagerecords per poll (alongside the existing S3 CSV presence check).Written by Cursor Bugbot for commit e58c734. Configure here.