-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration to remove expectation of demographics.ageRange #2670
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
data-serving/scripts/setup-db/migrations/20220506100633-remove-age-range.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,41 @@ | ||
/* | ||
* We need to ensure that ages are bucketed within five-year brackets, except for infants (below 1 year) | ||
* to improve the protection against deanonymisation in the case database. A previous migration introduced an | ||
* ageBuckets collection which represents an enumeration of the age ranges 0, 1-5, 6-10, 11-15, ..., 116-120. | ||
* | ||
* This one removes the now-redundant and inaccurate demographics.ageRange property from the cases collection. | ||
* The only information that defines the age for the case should be the buckets. | ||
*/ | ||
|
||
const ageRangeSchema ={ | ||
"bsonType": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"start": { | ||
"bsonType": "number", | ||
"minimum": 0, | ||
"maximum": 120 | ||
}, | ||
"end": { | ||
"bsonType": "number", | ||
"minimum": 0, | ||
"maximum": 120 | ||
} | ||
} | ||
}; | ||
|
||
module.exports = { | ||
async up(db, client) { | ||
let res = await db.command({listCollections: undefined, filter: {name: 'cases'}}); | ||
let schema = res.cursor.firstBatch[0].options.validator.$jsonSchema; | ||
delete schema.properties.demographics.properties.ageRange; | ||
await db.command({ collMod: 'cases', validator:{ $jsonSchema: schema } } ); | ||
}, | ||
|
||
async down(db, client) { | ||
let res = await db.command({listCollections: undefined, filter: {name: 'cases'}}); | ||
let schema = res.cursor.firstBatch[0].options.validator.$jsonSchema; | ||
schema.properties.demographics.properties.ageRange = ageRangeSchema; | ||
await db.command( { collMod: 'cases', validator:{ $jsonSchema: schema } } ); | ||
} | ||
}; |