Skip to content
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

[131] update mongodb validation for the case schema to allow search #136

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
9900cf5
Update libraries batch-2 first part
stanislaw-zakrzewski Apr 9, 2024
7cfbfb6
Move some testing to TODO
stanislaw-zakrzewski Apr 9, 2024
a8bbb46
Update Yup when
stanislaw-zakrzewski Apr 9, 2024
e5f5a65
update set field values
stanislaw-zakrzewski Apr 9, 2024
4e84668
Update breaking changes
stanislaw-zakrzewski Apr 9, 2024
9b411df
Update comment
stanislaw-zakrzewski Apr 9, 2024
a15ae3e
Remove unused
stanislaw-zakrzewski Apr 9, 2024
d3a0982
update datepicker
stanislaw-zakrzewski Apr 10, 2024
244a601
Update libraries batch-2 second part
stanislaw-zakrzewski Apr 10, 2024
13f2eea
Update return values of the functions for countries
stanislaw-zakrzewski Apr 10, 2024
b86a7d9
update typescript
stanislaw-zakrzewski Apr 10, 2024
b236761
Update mismatched versions
stanislaw-zakrzewski Apr 11, 2024
f202235
WIP update router and eslint + vite instead of cra
stanislaw-zakrzewski Apr 15, 2024
23a758f
Update tests for new vitest library
stanislaw-zakrzewski Apr 17, 2024
ce9f2b4
Update command for test and coverage
stanislaw-zakrzewski Apr 17, 2024
fd38634
Skip tests that were blocking flow
stanislaw-zakrzewski Apr 22, 2024
dc59615
Update Location.test.tsx
stanislaw-zakrzewski Apr 22, 2024
1ea9578
Merge branch 'main' into 121-update-libraries-batch-2
stanislaw-zakrzewski Apr 23, 2024
2513917
Update varaible name
stanislaw-zakrzewski Apr 23, 2024
be295b0
Fix merging issues
stanislaw-zakrzewski Apr 23, 2024
8db3a7b
Update index.tsx
stanislaw-zakrzewski Apr 29, 2024
65b0361
Update index.tsx
stanislaw-zakrzewski Apr 29, 2024
67eb629
WIP tests for location and landing page
stanislaw-zakrzewski Apr 30, 2024
f8d1389
Fixed all landing page tests
stanislaw-zakrzewski Apr 30, 2024
05975b0
Unskip and fix verification status indicator tests
stanislaw-zakrzewski Apr 30, 2024
b488de4
Fix automated source form tests
stanislaw-zakrzewski Apr 30, 2024
5143560
WIP unmocking EditCase tests
stanislaw-zakrzewski Apr 30, 2024
92198bc
Update EditCase.test.tsx
stanislaw-zakrzewski Apr 30, 2024
5e2042e
Fix viewcase tests
stanislaw-zakrzewski Apr 30, 2024
e94e3df
Resolve warnings regarding act
stanislaw-zakrzewski Apr 30, 2024
4813f85
Update Dockerfile
stanislaw-zakrzewski Apr 30, 2024
355aa1e
Update Location.test.tsx
stanislaw-zakrzewski Apr 30, 2024
8c8355f
Fix tests failing at the first day of the month
stanislaw-zakrzewski May 1, 2024
6b4ab01
Cleanup sourcetable
stanislaw-zakrzewski May 1, 2024
f22653b
Update Users Uploads and Sources tables
stanislaw-zakrzewski May 1, 2024
687caaa
Add backfill back
stanislaw-zakrzewski May 6, 2024
a6be882
Rename collection from cases to day0cases
stanislaw-zakrzewski May 6, 2024
0f8b973
Update day0cases.schema.json
stanislaw-zakrzewski May 6, 2024
8f421fe
Update day0cases.schema.json
stanislaw-zakrzewski May 7, 2024
04e9ab3
Initial schema work
stanislaw-zakrzewski May 14, 2024
222f0c2
initial schema work
stanislaw-zakrzewski May 14, 2024
63ff98c
Merge branch 'main' into 131-update-mongodb-validation-for-the-case-s…
stanislaw-zakrzewski May 28, 2024
edd00a4
Fix location lat/long update issue
stanislaw-zakrzewski Jun 7, 2024
a466e07
Merge branch 'main' into 131-update-mongodb-validation-for-the-case-s…
stanislaw-zakrzewski Oct 2, 2024
7d159ff
Add missing schema element - isGovernmentSource for Additional Sources
stanislaw-zakrzewski Oct 2, 2024
dc314b2
Update tests for searchbar and data guide
stanislaw-zakrzewski Oct 3, 2024
434e016
Update README.md
stanislaw-zakrzewski Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions data-serving/data-service/src/controllers/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,13 @@ export class CasesController {
res.status(201).json(result);
} catch (e) {
const err = e as Error;
if (err.name === 'MongoServerError') {
logger.error((e as any).errInfo);
res.status(422).json({
message: (err as any).errInfo,
});
return;
}
if (err instanceof GeocodeNotFoundError) {
res.status(404).json({
message: err.message,
Expand Down
99 changes: 51 additions & 48 deletions data-serving/scripts/setup-db/migrations/20210902121948-initial.js
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,
});
}

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'],
});
},
};
1 change: 1 addition & 0 deletions data-serving/scripts/setup-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lint": "tsc --noEmit && eslint '*/**/*.{js,ts,tsx}' --quiet --fix",
"import-sample-data": "python3 ./import-sample-data.py",
"migrate": "npm ci && migrate-mongo up",
"migrate-down": "npm ci && migrate-mongo down",
"delete-all-cases": "mongosh $CONN --eval 'db.cases.deleteMany({})'"
},
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"key": {
"demographics.occupation": "text",
"location.country": "text",
"location.city": "text",
"location.admin1": "text",
"location.admin2": "text",
"location.admin3": "text",
"caseReference.sourceUrl": "text",
"caseStatus": "text"
}
Expand Down Expand Up @@ -74,9 +76,29 @@
}
},
{
"name": "locationCityIdx",
"name": "locationAdmin1Idx",
"key": {
"location.city": -1
"location.admin1": -1
},
"collation": {
"locale": "en_US",
"strength": 2
}
},
{
"name": "locationAdmin2Idx",
"key": {
"location.admin2": -1
},
"collation": {
"locale": "en_US",
"strength": 2
}
},
{
"name": "locationAdmin3Idx",
"key": {
"location.admin3": -1
},
"collation": {
"locale": "en_US",
Expand Down
Loading
Loading