Skip to content

Commit

Permalink
Merge pull request #7557 from opencrvs/auto-pr-release-v1.6.0-7513-5766
Browse files Browse the repository at this point in the history
🍒 Merge changes from PR #7513 to release-v1.6.0
  • Loading branch information
Zangetsu101 authored Sep 2, 2024
2 parents 96f40c9 + 846df84 commit 94853bc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
6 changes: 0 additions & 6 deletions packages/metrics/test/setupJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ beforeEach(() => {
hits: [
{
_index: 'ocrvs',
_type: 'compositions',
_id: '0299daa0-fa97-439b-92ed-652d7db186c7',
_score: null,
_source: {
Expand Down Expand Up @@ -458,7 +457,6 @@ beforeEach(() => {
},
{
_index: 'ocrvs',
_type: 'compositions',
_id: 'ca09dfa9-9e31-40ed-8aa6-9446b4ceb71a',
_score: null,
_source: {
Expand Down Expand Up @@ -537,7 +535,6 @@ beforeEach(() => {
},
{
_index: 'ocrvs',
_type: 'compositions',
_id: '1a0dbdfd-550f-4113-ac23-e650596c7bea',
_score: null,
_source: {
Expand Down Expand Up @@ -598,7 +595,6 @@ beforeEach(() => {
},
{
_index: 'ocrvs',
_type: 'compositions',
_id: '9867aaef-b994-4744-b5b3-abdd3f520793',
_score: null,
_source: {
Expand Down Expand Up @@ -671,7 +667,6 @@ beforeEach(() => {
},
{
_index: 'ocrvs',
_type: 'compositions',
_id: 'b25ca75b-af0a-4cf4-94a8-359d1a7e190f',
_score: null,
_source: {
Expand Down Expand Up @@ -740,7 +735,6 @@ beforeEach(() => {
},
{
_index: 'ocrvs',
_type: 'compositions',
_id: 'b8779830-49ca-48ed-8a21-fd43121e65ce',
_score: null,
_source: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ export const up = async (db: Db, client: MongoClient) => {
{
$project: {
name: 1,
id: 1,

populations: {
$reduce: {
Expand Down Expand Up @@ -763,7 +764,7 @@ export const up = async (db: Db, client: MongoClient) => {
{ $unwind: '$daysInYear' },
{
$project: {
_id: { $concat: [{ $toString: '$name' }, '$daysInYear.date'] },
_id: { $concat: [{ $toString: '$id' }, '_', '$daysInYear.date'] },
name: 1,
date: { $dateFromString: { dateString: '$daysInYear.date' } },
estimatedNumberOfBirths: '$daysInYear.estimatedNumberOfBirths',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const up = async (db: Db, client: MongoClient) => {
}
/* ==============Create a new userroles collection============== */

await db.createCollection('userroles')
await createCollectionIfDoesNotExist(db, 'userroles')

const userRolesResult = await db.collection('userroles').insertMany(
UserRoles.map((userRole) => ({
Expand Down Expand Up @@ -262,7 +262,7 @@ export const up = async (db: Db, client: MongoClient) => {
await db.collection('roles').rename('systemroles')
} else {
//create a new 'systemroles' collection
await db.createCollection('systemroles')
await createCollectionIfDoesNotExist(db, 'systemroles')

//insert all system roles to 'systemroles' collection
await db.collection('systemroles').insertMany(
Expand All @@ -289,7 +289,8 @@ export const down = async (db: Db, client: MongoClient) => {
try {
/* ==============Drop collection userroles============== */

await db.dropCollection('userroles')
if (await checkIfCollectionExists(db, 'userroles'))
await db.dropCollection('userroles')

/* ==============Migration for "users" Collection============== */

Expand Down Expand Up @@ -352,3 +353,22 @@ export async function getTotalDocCountByCollectionName(
export async function getUserCursor(db: Db, limit = 50, skip = 0) {
return db.collection('users').find({}, { limit, skip })
}

async function createCollectionIfDoesNotExist(db: Db, collectionName: string) {
const collectionExists = await checkIfCollectionExists(db, collectionName)

if (!collectionExists) {
await db.createCollection(collectionName)
console.log(`${collectionName} collection created`)
} else {
console.log(`${collectionName} collection already exists`)
}
}

async function checkIfCollectionExists(db: Db, collectionName: string) {
const collectionExists = await db
.listCollections({ name: collectionName })
.hasNext()

return collectionExists
}
4 changes: 0 additions & 4 deletions packages/search/src/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2800,7 +2800,6 @@ export const mockSearchResponse = {
hits: [
{
_index: 'ocrvs',
_type: 'compositions',
_id: 'c99e8d62-335e-458d-9fcc-45ec5836c404',
_score: 2.7509375,
_source: {
Expand Down Expand Up @@ -2833,7 +2832,6 @@ export const mockSearchResponseWithoutCreatedBy = {
hits: [
{
_index: 'ocrvs',
_type: 'compositions',
_id: 'c99e8d62-335e-458d-9fcc-45ec5836c404',
_score: 2.7509375,
_source: {
Expand Down Expand Up @@ -3387,7 +3385,6 @@ export const mockSearchResult = {
hits: [
{
_index: 'ocrvs',
_type: 'compositions',
_id: 'BGM9CA2',
_score: 1,
_source: {
Expand All @@ -3404,7 +3401,6 @@ export const mockSearchResult = {
},
{
_index: 'ocrvs',
_type: 'compositions',
_id: 'DGM9CA2',
_score: 1,
_source: {
Expand Down

0 comments on commit 94853bc

Please sign in to comment.