-
Notifications
You must be signed in to change notification settings - Fork 1
imp(workers): move timestamp out of event payload #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6cc15f7
chore(): update types deps
e11sy 0732960
imp(): update worker task types
e11sy fcb37e9
imp(): update worker handlers
e11sy f9effb8
feat(): migration for moving timestamp out of payload
e11sy 74c48dc
fix(): tests fixed
e11sy 78c9223
imp(): naming, worker tasks (default, sentry, js, grouper)
e11sy 1b9f811
chore(): update from master
e11sy da487bf
imp(): imp worker tasks
e11sy 99805e6
imp(sentry): types cast
e11sy 5c52181
fix types
neSpecc d252bce
chore(): clean up
e11sy 2363bba
fix(): tests fixed
e11sy 74a7612
fix(): tests minor fixes
e11sy ff11216
deps: update types dependency
e11sy c3d2145
fix(): tests minor fixes
e11sy 986cd37
fix(): types fix
e11sy d289f51
chore(): get rid of EventDataAccepted
e11sy 9945f2b
chore: lint remove redundant imports
e11sy 399286f
fix(): sentry tests fixed
e11sy 97721a2
chore: fix lint
e11sy 3e207c2
imp(): change migration to use bulkWrite instead of cursor
e11sy b5f3b4e
imp(): js worker event type improved
e11sy e837f20
chore(): fix lint
e11sy 869a2d6
imp(): add convertor script
e11sy 494c26f
chore: lint fix
e11sy cb09cba
imp: convertor
e11sy dfe374b
chore(): converter script improvements
e11sy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
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
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
162 changes: 162 additions & 0 deletions
162
migrations/20250707160120-move-timestamp-to-event-level.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| /** | ||
| * This migration moves `payload.timestamp` to top-level `timestamp` | ||
| * for both `events:*` and `repetitions:*` collections. | ||
| */ | ||
|
|
||
| module.exports = { | ||
| async up(db) { | ||
| const collections = await db.listCollections({}, { | ||
| authorizedCollections: true, | ||
| nameOnly: true, | ||
| }).toArray(); | ||
|
|
||
| // Separate collections by prefix | ||
| const eventCollections = collections | ||
| .filter(col => /^events:/.test(col.name)) | ||
| .map(col => col.name); | ||
|
|
||
| const repetitionCollections = collections | ||
| .filter(col => /^repetitions:/.test(col.name)) | ||
| .map(col => col.name); | ||
|
|
||
| // Step 1: Process event collections | ||
| for (const collectionName of eventCollections) { | ||
| await db.collection(collectionName).updateMany( | ||
| { 'payload.timestamp': { $exists: true } }, | ||
| [ | ||
| { | ||
| $set: { | ||
| timestamp: { $toDouble: "$payload.timestamp" }, | ||
| }, | ||
| }, | ||
| { | ||
| $unset: "payload.timestamp", | ||
| }, | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| // Step 2: Process repetition collections | ||
| for (const collectionName of repetitionCollections) { | ||
| const projectId = collectionName.split(':')[1]; | ||
| const collection = db.collection(collectionName); | ||
|
|
||
| // Step 2.1: First, handle documents where payload.timestamp exists | ||
| await collection.updateMany( | ||
| { 'payload.timestamp': { $exists: true } }, | ||
| [ | ||
| { | ||
| $set: { | ||
| timestamp: { $toDouble: "$payload.timestamp" }, // Convert payload.timestamp to number | ||
| }, | ||
| }, | ||
| { | ||
| $unset: "payload.timestamp", // Remove payload.timestamp | ||
| }, | ||
| ] | ||
| ); | ||
|
|
||
| const pipeline = [ | ||
| { | ||
| $match: { | ||
| $or : [ | ||
| { "payload.timestamp": { $exists: false } }, | ||
| { payload: { $exists: false } }, | ||
| ], | ||
| timestamp: { $exists: false }, | ||
| groupHash: { $exists: true } | ||
| } | ||
| }, | ||
| { | ||
| $lookup: { | ||
| from: `events:${projectId}`, // dynamically referencing the events collection | ||
| localField: "groupHash", // field from repetitions collection | ||
| foreignField: "groupHash", // field in the events collection | ||
| as: "eventData" // alias for the matched data | ||
| } | ||
| }, | ||
| { | ||
| $unwind: { | ||
| path: "$eventData", // we expect only one match per groupHash | ||
| preserveNullAndEmptyArrays: true // allow documents with no matching event | ||
| } | ||
| }, | ||
| { | ||
| $match: { | ||
| "eventData.timestamp": { $exists: true } // only proceed if event.timestamp exists | ||
| } | ||
| }, | ||
| { | ||
| $project: { | ||
| _id: 1, | ||
| eventTimestamp: { $toDouble: "$eventData.timestamp"} | ||
| } | ||
| } | ||
| ]; | ||
|
|
||
| const matchedDocs = await collection.aggregate(pipeline).toArray(); | ||
|
|
||
| const bulkOps = matchedDocs.map(doc => ({ | ||
| updateOne: { | ||
| filter: { _id: doc._id }, | ||
| update: { | ||
| $set: { timestamp: doc.eventTimestamp } // Set the timestamp from the event | ||
| } | ||
| } | ||
| })); | ||
|
|
||
| if (bulkOps.length > 0) { | ||
| await collection.bulkWrite(bulkOps); | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| async down(db) { | ||
| const collections = await db.listCollections({}, { | ||
| authorizedCollections: true, | ||
| nameOnly: true, | ||
| }).toArray(); | ||
|
|
||
| const eventCollections = collections | ||
| .filter(col => /^events:/.test(col.name)) | ||
| .map(col => col.name); | ||
|
|
||
| const repetitionCollections = collections | ||
| .filter(col => /^repetitions:/.test(col.name)) | ||
| .map(col => col.name); | ||
|
|
||
| // Revert event collections | ||
| for (const collectionName of eventCollections) { | ||
| await db.collection(collectionName).updateMany( | ||
| { timestamp: { $exists: true } }, | ||
| [ | ||
| { | ||
| $set: { | ||
| 'payload.timestamp': '$timestamp', | ||
| }, | ||
| }, | ||
| { | ||
| $unset: { 'timestamp': "" }, | ||
| }, | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| // Revert repetition collections | ||
| for (const collectionName of repetitionCollections) { | ||
| await db.collection(collectionName).updateMany( | ||
| { timestamp: { $exists: true } }, | ||
| [ | ||
| { | ||
| $set: { | ||
| 'payload.timestamp': '$timestamp', | ||
| }, | ||
| }, | ||
| { | ||
| $unset: { 'timestamp': "" }, | ||
| }, | ||
| ] | ||
| ); | ||
| } | ||
| }, | ||
| }; |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment pls