-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mrf): retain workflow through a submission lifetime (#7087)
* feat: retain workflow through a submission lifetime * test: fix submission model tests with workflow object * fix: add db migration script * chore: update package-lock for virus scanner
- Loading branch information
Showing
10 changed files
with
1,219 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
99 changes: 99 additions & 0 deletions
99
scripts/20240215_mrf-retain-workflow-in-submissions/mrf-retain-workflow-in-submissions.js
This file contains 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,99 @@ | ||
/* eslint-disable */ | ||
|
||
// Creates a new workflow key in all existing mrf submissions, populated with | ||
// the form's existing workflow. From this point on, workflows should be captured | ||
// when the submission is initially created (i.e. the workflow is started), | ||
|
||
// BEFORE | ||
// COUNT existing number of MRF submissions with no workflow key | ||
db.submissions.aggregate([ | ||
{ | ||
$match: { | ||
submissionType: 'multirespondentSubmission', | ||
workflow: { $exists: false }, | ||
}, | ||
}, | ||
{ | ||
$lookup: { | ||
from: 'forms', | ||
localField: 'form', | ||
foreignField: '_id', | ||
as: 'forms', | ||
}, | ||
}, | ||
{ | ||
$addFields: { | ||
formWorkflow: { $first: '$forms.workflow' }, | ||
}, | ||
}, | ||
{ | ||
$match: { | ||
formWorkflow: { $exists: true }, | ||
}, | ||
}, | ||
{ | ||
$count: 'count', | ||
}, | ||
]) | ||
|
||
// UPDATE | ||
db.submissions.aggregate([ | ||
{ | ||
$match: { | ||
submissionType: 'multirespondentSubmission', | ||
}, | ||
}, | ||
{ | ||
$lookup: { | ||
from: 'forms', | ||
localField: 'form', | ||
foreignField: '_id', | ||
as: 'forms', | ||
}, | ||
}, | ||
{ | ||
$addFields: { | ||
workflow: { $first: '$forms.workflow' }, | ||
}, | ||
}, | ||
{ | ||
$merge: { | ||
into: 'submissions', | ||
on: '_id', | ||
whenNotMatched: 'discard', | ||
}, | ||
}, | ||
]) | ||
|
||
// AFTER | ||
// Count number of MRF submissions with workflow key | ||
// Expect this to match the COUNT in BEFORE | ||
db.submissions.aggregate([ | ||
{ | ||
$match: { | ||
submissionType: 'multirespondentSubmission', | ||
workflow: { $exists: true }, | ||
}, | ||
}, | ||
{ | ||
$lookup: { | ||
from: 'forms', | ||
localField: 'form', | ||
foreignField: '_id', | ||
as: 'forms', | ||
}, | ||
}, | ||
{ | ||
$addFields: { | ||
formWorkflow: { $first: '$forms.workflow' }, | ||
}, | ||
}, | ||
{ | ||
$match: { | ||
formWorkflow: { $exists: true }, | ||
}, | ||
}, | ||
{ | ||
$count: 'count', | ||
}, | ||
]) |
Oops, something went wrong.