Repository navigation
feat(scripts): remove duplicate paper requests before the unique index - #579
Open
Rithish-2914 wants to merge 1 commit into
Open
Rithish-2914 wants to merge 1 commit into
Rithish-2914 wants to merge 1 commit into
Conversation
CodeChefVIT#571 adds a unique index on subject + exam + slot + year to PaperRequest, but production already has duplicate requests, so the index can't be built. scripts/dedupe-paper-requests.mjs (npm run dedupe-requests): - dry run by default, lists duplicate groups and what would change - groups by the four fields with surrounding spaces ignored, matching the trimming /api/request does after CodeChefVIT#571 - --delete keeps the oldest request per group, removes the rest and trims kept rows, after backing them up to paper-request-duplicates-<time>.json (EJSON, so ids and dates restore exactly; gitignored) - reports exams outside the allowed list without touching them - checks again afterwards and fails if new duplicates came in meanwhile
Collaborator
|
looks safe to run 👀 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
#571 adds a unique index on subject + exam + slot + year to
PaperRequest, but prod already has duplicate requests, so Mongo can't build the index. This script cleans them up so #571 can be merged.Corresponding issue: related to #550, unblocks #571
Changes
scripts/dedupe-paper-requests.mjs, run withnpm run dedupe-requests--delete: keeps the oldest request in each group, removes the rest, trims kept rowspaper-request-duplicates-<time>.json(EJSON, gitignored)--collection=<name>to point at another collectionTesting
--deleteon an in-memory MongoDB seeded with exact duplicates, space-only duplicates, a request withoutcreatedAtand an unknown exam: keeps the oldest, trims, backup restores ids and dates exactly, unique index builds afterwards, second run does nothingAdditional Notes
Order for prod:
npm run dedupe-requests→ check the output →npm run dedupe-requests -- --delete→ merge #571 soon after, since repeat requests can come in before it's live (re-running the script fixes that).Needs Node 20.6+ for
--env-file.