-
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.
[131] update mongodb validation for the case schema to allow search (#…
…136) * Update libraries batch-2 first part * Move some testing to TODO * Update Yup when * update set field values * Update breaking changes * Update comment * Remove unused * update datepicker * Update libraries batch-2 second part * Update return values of the functions for countries * update typescript * Update mismatched versions * WIP update router and eslint + vite instead of cra * Update tests for new vitest library * Update command for test and coverage * Skip tests that were blocking flow * Update Location.test.tsx * Update varaible name * Fix merging issues * Update index.tsx * Update index.tsx * WIP tests for location and landing page * Fixed all landing page tests * Unskip and fix verification status indicator tests * Fix automated source form tests * WIP unmocking EditCase tests * Update EditCase.test.tsx * Fix viewcase tests * Resolve warnings regarding act * Update Dockerfile * Update Location.test.tsx * Fix tests failing at the first day of the month * Cleanup sourcetable * Update Users Uploads and Sources tables * Add backfill back It was removed after splitting one component into multiple * Rename collection from cases to day0cases * Update day0cases.schema.json * Update day0cases.schema.json * Initial schema work * initial schema work * Fix location lat/long update issue * Add missing schema element - isGovernmentSource for Additional Sources * Update tests for searchbar and data guide * Update README.md
- Loading branch information
1 parent
25a86d5
commit 929ea2a
Showing
11 changed files
with
348 additions
and
91 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: 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
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.