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

Feat upgrade mongo #8106

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion development-environment/clear-all-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ print_usage_and_exit () {
DIR=$(pwd)

# It's fine if these fail as it might be that the databases do not exist at this point
docker run --rm --network=opencrvs_default mongo:4.4 mongo --host mongo1 --eval "\
docker run --rm --network=opencrvs_default mongo:5.0 mongo --host mongo1 --eval "\
db.getSiblingDB('hearth-dev').dropDatabase();\
db.getSiblingDB('openhim-dev').dropDatabase();\
db.getSiblingDB('user-mgnt').dropDatabase();\
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ volumes:
metricbeat:
services:
mongo1:
image: mongo:4.4
image: mongo:5.0
restart: unless-stopped

redis:
Expand Down
2 changes: 1 addition & 1 deletion packages/events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@trpc/server": "^11.0.0-rc.532",
"app-module-path": "^2.2.0",
"envalid": "^8.0.0",
"mongodb": "6.9.0",
"mongodb": "6.11.0",
"superjson": "1.9.0-0",
"tsconfig-paths": "^3.13.0",
"zod": "^3.23.8"
Expand Down
2 changes: 1 addition & 1 deletion packages/metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"jsonwebtoken": "^9.0.0",
"jwt-decode": "^3.0.0",
"lodash": "^4.17.21",
"mongodb": "^4.17.1",
"mongodb": "6.11.0",
"mongoose": "^6.11.3",
"node-fetch": "^2.6.7",
"pino": "^7.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/migration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
"influx": "^5.0.7",
"is-svg": "^4.3.2",
"lodash-es": "^4.17.21",
"migrate-mongo": "^10.0.0",
"migrate-mongo": "^11.0.0",
"minio": "^7.0.33",
"mongoose": "^6.11.3",
"tsx": "^4.15.7",
"uuid": "^3.2.1"
},
"devDependencies": {
"@types/fhir": "0.0.30",
"mongodb": "^4.17.1",
"mongodb": "6.11.0",
"prettier": "^2.5.0",
"rimraf": "^5.0.0",
"typescript": "5.6.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import isSvg from 'is-svg'
import { uploadSvgToMinio } from '../../utils/minio-helper.js'
import { ICertificateTemplateData } from '../../utils/migration-interfaces.js'
import { Db, MongoClient } from 'mongodb'
import { Db, MongoClient, ObjectId } from 'mongodb'

export const up = async (db: Db, client: MongoClient) => {
const session = client.startSession()
Expand All @@ -32,7 +32,7 @@ export const up = async (db: Db, client: MongoClient) => {
const uri = await uploadSvgToMinio(svgCode)
await db
.collection('certificates')
.updateOne({ _id }, { $set: { svgCode: uri } })
.updateOne({ _id: new ObjectId(_id) }, { $set: { svgCode: uri } })
} catch (err) {
console.log(`Saving certificate template failed with error: ${err}`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const up = async (db: Db, client: MongoClient) => {
)
if (hasDocumentSection) {
await db
.collection('Composition')
.collection<fhir.Composition>('Composition')
.updateOne(
{ id: compositionHistory[correctionIndex].id },
{ $push: { section: hasDocumentSection } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,23 @@ export const up = async (db: Db, client: MongoClient) => {
{ $set: { 'code.1.coding.0.code': titleCase(typeCode) } }
)
} else {
await db.collection('PractitionerRole').updateOne(
{ id: practitionerRole?.id },
{
$push: {
code: {
coding: [
{
system: 'http://opencrvs.org/specs/types',
code: JSON.stringify(usersLabels[roleCode])
}
]
await db
.collection<fhir.PractitionerRole>('PractitionerRole')
.updateOne(
{ id: practitionerRole?.id },
{
$push: {
code: {
coding: [
{
system: 'http://opencrvs.org/specs/types',
code: JSON.stringify(usersLabels[roleCode])
}
]
}
}
}
}
)
)
}
}
skip += limit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import { Db, MongoClient } from 'mongodb'
import * as mongoose from 'mongoose'
import { Db, MongoClient, ObjectId } from 'mongodb'

const USER_MGNT_MONGO_URL =
process.env.USER_MGNT_MONGO_URL || 'mongodb://localhost/user-mgnt'

export const up = async (db: Db, client: MongoClient) => {
const ObjectId = mongoose.Types.ObjectId
const session = client.startSession()
const userManagementClient = new MongoClient(USER_MGNT_MONGO_URL)
const connectedUserManagementClient = await userManagementClient.connect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import { Db, MongoClient } from 'mongodb'
import { Db, MongoClient, ObjectId } from 'mongodb'
import { isEmpty } from 'lodash-es'

function derivePartOfFromAddress(address: fhir.Address) {
Expand Down Expand Up @@ -57,7 +57,7 @@ export const up = async (db: Db, client: MongoClient) => {
})

patients.updateOne(
{ _id: patient._id },
{ _id: new ObjectId(patient._id as string) },
{ $set: { address: updatedAddresses } }
)
})
Expand All @@ -73,7 +73,7 @@ export const up = async (db: Db, client: MongoClient) => {

if (partOf) {
locations.updateOne(
{ _id: location._id },
{ _id: new ObjectId(location._id as string) },
{ $set: { partOf: { reference: `Location/${partOf}` } } }
)
}
Expand Down Expand Up @@ -103,7 +103,7 @@ export const down = async (db: Db, client: MongoClient) => {
})

patients.updateOne(
{ _id: patient._id },
{ _id: new ObjectId(patient._id as string) },
{ $set: { address: updatedAddresses } }
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const up = async (db: Db, client: MongoClient) => {
await session.withTransaction(async () => {
console.log('Checking if mobile field already have indices')
const indexes = Object.keys(
(await db.collection('users').stats()).indexSizes
(await db.command({ collStats: 'users' })).indexSizes
)
const mobileHasIndex = indexes.some(
(index) => index.split('_')[0] === ('mobile' as const)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export const up = async (db: Db, client: MongoClient) => {

export const down = async (db: Db, client: MongoClient) => {
await db
.collection('users')
.collection<fhir.Practitioner>('users')
.updateOne({ username: 'o.admin' }, { $pull: { scope: 'bypassratelimit' } })
}
4 changes: 2 additions & 2 deletions packages/migration/src/utils/openhim-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function addRouteToChannel(
route: Route
) {
await db
.collection('channels')
.collection<Channel>('channels')
.updateOne({ name: channelName }, { $push: { routes: route } })
}

Expand All @@ -90,7 +90,7 @@ export async function removeRouteFromChannel(
routeName: string
) {
await db
.collection('channels')
.collection<Channel>('channels')
.updateOne(
{ name: channelName },
{ $pull: { routes: { name: routeName } } }
Expand Down
2 changes: 1 addition & 1 deletion packages/search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"joi": "^17.3.0",
"jsonwebtoken": "^9.0.0",
"jwt-decode": "^3.0.0",
"mongodb": "4.17.2",
"mongodb": "6.11.0",
"node-fetch": "^2.6.7",
"pino": "^7.0.0",
"short-uid": "^0.1.0",
Expand Down
29 changes: 17 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5798,7 +5798,7 @@
dependencies:
sparse-bitfield "^3.0.3"

"@mongodb-js/saslprep@^1.1.5":
"@mongodb-js/saslprep@^1.1.5", "@mongodb-js/saslprep@^1.1.9":
version "1.1.9"
resolved "https://registry.yarnpkg.com/@mongodb-js/saslprep/-/saslprep-1.1.9.tgz#e974bab8eca9faa88677d4ea4da8d09a52069004"
integrity sha512-tVkljjeEaAhCqTzajSdgbQ6gE6f3oneVwa3iXR6csiEwXXOFsiC6Uh9iAjAhXPtqa/XMDHWjjeNH/77m/Yq2dw==
Expand Down Expand Up @@ -11337,6 +11337,11 @@ bson@^4.7.2:
dependencies:
buffer "^5.6.0"

bson@^6.10.0:
version "6.10.0"
resolved "https://registry.yarnpkg.com/bson/-/bson-6.10.0.tgz#559c767cc8b605c3ab14e5896214c8f2abdd6a12"
integrity sha512-ROchNosXMJD2cbQGm84KoP7vOGPO6/bOAW0veMMbzhXLqoZptcaYRVLitwvuhwhjjpU1qP4YZRWLhgETdgqUQw==

bson@^6.7.0:
version "6.9.0"
resolved "https://registry.yarnpkg.com/bson/-/bson-6.9.0.tgz#2be50049430dceaa9300402520fe03e4ed5fdfd6"
Expand Down Expand Up @@ -19136,10 +19141,10 @@ micromatch@~4.0.8:
braces "^3.0.3"
picomatch "^2.3.1"

migrate-mongo@^10.0.0:
version "10.0.0"
resolved "https://registry.npmjs.org/migrate-mongo/-/migrate-mongo-10.0.0.tgz"
integrity sha512-QA/bBKNMq/FmuK3fDbgwfNoW2riiU1wLDWGXv/tGhUItPLGqcciPPmu29SrnYAzRKMOVaGEXxzmrBs1zp5cQ7Q==
migrate-mongo@^11.0.0:
version "11.0.0"
resolved "https://registry.yarnpkg.com/migrate-mongo/-/migrate-mongo-11.0.0.tgz#d1b2291624fe8e134a0666ca77ad2fa18f42e337"
integrity sha512-GB/gHzUwp/fL1w6ksNGihTyb+cSrm6NbVLlz1OSkQKaLlzAXMwH7iKK2ZS7W5v+I8vXiY2rL58WTUZSAL6QR+A==
dependencies:
cli-table3 "^0.6.1"
commander "^9.1.0"
Expand Down Expand Up @@ -19499,7 +19504,7 @@ mongodb-memory-server@^10.1.2:
mongodb-memory-server-core "10.1.2"
tslib "^2.7.0"

[email protected], mongodb@^4.17.1:
[email protected]:
version "4.17.2"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-4.17.2.tgz#237c0534e36a3449bd74c6bf6d32f87a1ca7200c"
integrity sha512-mLV7SEiov2LHleRJPMPrK2PMyhXFZt2UQLC4VD4pnth3jMjYKHhtqfwwkkvS/NXuo/Fp3vbhaNcXrIDaLRb9Tg==
Expand All @@ -19511,13 +19516,13 @@ [email protected], mongodb@^4.17.1:
"@aws-sdk/credential-providers" "^3.186.0"
"@mongodb-js/saslprep" "^1.1.0"

mongodb@6.9.0:
version "6.9.0"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-6.9.0.tgz#743ebfff6b3c14b04ac6e00a55e30d4127d3016d"
integrity sha512-UMopBVx1LmEUbW/QE0Hw18u583PEDVQmUmVzzBRH0o/xtE9DBRA5ZYLOjpLIa03i8FXjzvQECJcqoMvCXftTUA==
mongodb@6.11.0:
version "6.11.0"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-6.11.0.tgz#d09bc055e1e784849279dc41eb2cd1537a0488a0"
integrity sha512-yVbPw0qT268YKhG241vAMLaDQAPbRyTgo++odSgGc9kXnzOujQI60Iyj23B9sQQFPSvmNPvMZ3dsFz0aN55KgA==
dependencies:
"@mongodb-js/saslprep" "^1.1.5"
bson "^6.7.0"
"@mongodb-js/saslprep" "^1.1.9"
bson "^6.10.0"
mongodb-connection-string-url "^3.0.0"

mongodb@^6.9.0:
Expand Down
Loading