-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 93-add-bulk-verification
- Loading branch information
Showing
17 changed files
with
580 additions
and
180 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
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
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: 51 additions & 48 deletions
99
data-serving/scripts/setup-db/migrations/20210902121948-initial.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 |
---|---|---|
@@ -1,57 +1,60 @@ | ||
const fs = require('fs'); | ||
|
||
module.exports = { | ||
async up(db, client) { | ||
await createCollectionValidationAndIndexes( | ||
db, | ||
'cases', | ||
'schemas/cases.schema.json', | ||
'schemas/cases.indexes.json' | ||
); | ||
|
||
await createCollectionValidationAndIndexes( | ||
db, | ||
'sources', | ||
'schemas/sources.schema.json', | ||
'schemas/sources.indexes.json' | ||
); | ||
}, | ||
|
||
async down(db, client) { | ||
// initial migration has no rollback | ||
} | ||
async up(db, client) { | ||
await createCollectionValidationAndIndexes( | ||
db, | ||
'day0cases', | ||
'schemas/day0cases.schema.json', | ||
'schemas/day0cases.indexes.json', | ||
); | ||
|
||
await createCollectionValidationAndIndexes( | ||
db, | ||
'sources', | ||
'schemas/sources.schema.json', | ||
'schemas/sources.indexes.json', | ||
); | ||
}, | ||
|
||
async down(db, client) { | ||
// initial migration has no rollback | ||
}, | ||
}; | ||
|
||
async function createCollectionValidationAndIndexes(db, collectionName, schemaPath, indexPath) { | ||
const schemaFile = await fs.promises.readFile(schemaPath); | ||
const schema = JSON.parse(schemaFile); | ||
async function createCollectionValidationAndIndexes( | ||
db, | ||
collectionName, | ||
schemaPath, | ||
indexPath, | ||
) { | ||
const schemaFile = await fs.promises.readFile(schemaPath); | ||
const schema = JSON.parse(schemaFile); | ||
|
||
const indexFile = await fs.promises.readFile(indexPath); | ||
const indexes = JSON.parse(indexFile); | ||
/* | ||
* because this migration might run against a DB from before we had the migrations infra, | ||
* check whether the collection already exists. If it does, then modify its validation schema. | ||
* If it doesn't, then create it. | ||
*/ | ||
try { | ||
await db.collection(collectionName); | ||
await db.command({ | ||
collMod: collectionName, | ||
validator: schema, | ||
}); | ||
} catch { | ||
await db.createCollection(collectionName, { | ||
validator: schema, | ||
}); | ||
} | ||
|
||
const collection = db.collection(collectionName); | ||
await collection.dropIndexes(); | ||
|
||
const indexFile = await fs.promises.readFile(indexPath); | ||
const indexes = JSON.parse(indexFile); | ||
/* | ||
* because this migration might run against a DB from before we had the migrations infra, | ||
* check whether the collection already exists. If it does, then modify its validation schema. | ||
* If it doesn't, then create it. | ||
*/ | ||
try { | ||
await db.collection(collectionName); | ||
await db.command({ | ||
collMod: collectionName, | ||
validator: schema, | ||
}); | ||
} | ||
catch { | ||
await db.createCollection(collectionName, { | ||
validator: schema, | ||
createIndexes: collectionName, | ||
indexes: indexes, | ||
}); | ||
} | ||
|
||
const collection = db.collection(collectionName); | ||
await collection.dropIndexes(); | ||
|
||
await db.command({ | ||
createIndexes: collectionName, | ||
indexes: indexes, | ||
}); | ||
} | ||
|
44 changes: 22 additions & 22 deletions
44
data-serving/scripts/setup-db/migrations/20210922082905-additional-case-indexes.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 |
---|---|---|
@@ -1,29 +1,29 @@ | ||
const indexes = [ | ||
{ | ||
name: 'byGenderAndCountry', | ||
key: { | ||
'demographics.gender': -1, | ||
'location.countryISO3': -1 | ||
{ | ||
name: 'byGenderAndCountry', | ||
key: { | ||
'demographics.gender': -1, | ||
'location.countryISO3': -1, | ||
}, | ||
collation: { | ||
locale: 'en_US', | ||
strength: 2, | ||
}, | ||
}, | ||
collation: { | ||
locale: 'en_US', | ||
strength: 2, | ||
}, | ||
} | ||
]; | ||
|
||
module.exports = { | ||
async up(db, client) { | ||
await db.command({ | ||
createIndexes: 'cases', | ||
indexes: indexes, | ||
}); | ||
}, | ||
async up(db, client) { | ||
await db.command({ | ||
createIndexes: 'day0cases', | ||
indexes: indexes, | ||
}); | ||
}, | ||
|
||
async down(db, client) { | ||
await db.command({ | ||
dropIndexes: 'cases', | ||
index: ['byGenderAndCountry'] | ||
}); | ||
} | ||
async down(db, client) { | ||
await db.command({ | ||
dropIndexes: 'day0cases', | ||
index: ['byGenderAndCountry'], | ||
}); | ||
}, | ||
}; |
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
Oops, something went wrong.