Skip to content

Add scripts - #7

Open
stephtea wants to merge 2 commits into
developfrom
stephen-additions-1
Open

Add scripts#7
stephtea wants to merge 2 commits into
developfrom
stephen-additions-1

Conversation

@stephtea

@stephtea stephtea commented Mar 2, 2026

Copy link
Copy Markdown

Add scripts:

  • resend poll creation SQS
  • Moving a poll from a user with wrong email to a user with the correct email and deleting the wrong email user account

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.ts to re-enqueue a pollCreation SQS message for a specific poll after prompting for confirmation.

Updates scripts/poll-problem.ts to also report the count of pollIndividualMessage records per poll (alongside the existing S3 CSV presence check).

Written by Cursor Bugbot for commit e58c734. Configure here.

stephtea added 2 commits March 2, 2026 12:54
add scripts
comments

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.id check that aborts with a clear message before any transaction logic runs.

Create PR

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}`);
This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Comment thread scripts/fix-poll-user.ts
if (!correctUser) {
console.error(`No user found with email: ${correctEmail}`);
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Additional Locations (1)

Fix in Cursor Fix in Web

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