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

UBERF-7749: Use MONGO_OPTIONS properly #6200

Merged
merged 1 commit into from
Jul 31, 2024
Merged
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
34 changes: 17 additions & 17 deletions dev/tool/src/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import task, { type ProjectType, type Task, type TaskType } from '@hcengineering
import { updateYDocContent } from '@hcengineering/text'
import tracker from '@hcengineering/tracker'
import { deepEqual } from 'fast-equals'
import { type Db, MongoClient } from 'mongodb'
import { type Db } from 'mongodb'

export async function cleanWorkspace (
ctx: MeasureContext,
Expand Down Expand Up @@ -157,10 +157,10 @@ export async function cleanWorkspace (
}
}

const client = new MongoClient(mongoUrl)
const client = getMongoClient(mongoUrl)
try {
await client.connect()
const db = getWorkspaceDB(client, workspaceId)
const _client = await client.getClient()
const db = getWorkspaceDB(_client, workspaceId)

if (opt.removedTx) {
const txes = await db.collection(DOMAIN_TX).find({}).toArray()
Expand All @@ -173,7 +173,7 @@ export async function cleanWorkspace (
}
}
} finally {
await client.close()
client.close()
}
} catch (err: any) {
console.trace(err)
Expand Down Expand Up @@ -420,10 +420,10 @@ export async function fixSkills (
const connection = (await connect(transactorUrl, workspaceId, undefined, {
mode: 'backup'
})) as unknown as CoreClient & BackupClient
const client = new MongoClient(mongoUrl)
const client = getMongoClient(mongoUrl)
try {
await client.connect()
const db = getWorkspaceDB(client, workspaceId)
const _client = await client.getClient()
const db = getWorkspaceDB(_client, workspaceId)

async function fixCount (): Promise<void> {
console.log('fixing ref-count...')
Expand Down Expand Up @@ -664,7 +664,7 @@ export async function fixSkills (
} catch (err: any) {
console.trace(err)
} finally {
await client.close()
client.close()
await connection.close()
}
}
Expand All @@ -689,10 +689,10 @@ export async function restoreRecruitingTaskTypes (
mode: 'backup',
model: 'upgrade'
})) as unknown as CoreClient & BackupClient
const client = new MongoClient(mongoUrl)
const client = getMongoClient(mongoUrl)
try {
await client.connect()
const db = getWorkspaceDB(client, workspaceId)
const _client = await client.getClient()
const db = getWorkspaceDB(_client, workspaceId)

// Query all vacancy project types creations (in Model)
// We only update new project types in model here and not old ones in spaces
Expand Down Expand Up @@ -839,7 +839,7 @@ export async function restoreRecruitingTaskTypes (
} catch (err: any) {
console.trace(err)
} finally {
await client.close()
client.close()
await connection.close()
}
}
Expand All @@ -853,10 +853,10 @@ export async function restoreHrTaskTypesFromUpdates (
mode: 'backup',
model: 'upgrade'
})) as unknown as CoreClient & BackupClient
const client = new MongoClient(mongoUrl)
const client = getMongoClient(mongoUrl)
try {
await client.connect()
const db = getWorkspaceDB(client, workspaceId)
const _client = await client.getClient()
const db = getWorkspaceDB(_client, workspaceId)
const hierarchy = connection.getHierarchy()
const descr = connection.getModel().getObject(recruit.descriptors.VacancyType)
const knownCategories = [
Expand Down Expand Up @@ -1047,7 +1047,7 @@ export async function restoreHrTaskTypesFromUpdates (
} catch (err: any) {
console.trace(err)
} finally {
await client.close()
client.close()
await connection.close()
}
}
Expand Down
11 changes: 5 additions & 6 deletions dev/tool/src/elastic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,24 @@

import { Client as ElasticClient } from '@elastic/elasticsearch'
import core, { DOMAIN_DOC_INDEX_STATE, toWorkspaceString, type WorkspaceId } from '@hcengineering/core'
import { getWorkspaceDB } from '@hcengineering/mongo'
import { getMongoClient, getWorkspaceDB } from '@hcengineering/mongo'
import { type StorageAdapter } from '@hcengineering/server-core'
import { MongoClient } from 'mongodb'

export async function rebuildElastic (
mongoUrl: string,
workspaceId: WorkspaceId,
storageAdapter: StorageAdapter,
elasticUrl: string
): Promise<void> {
const client = new MongoClient(mongoUrl)
const client = getMongoClient(mongoUrl)
try {
await client.connect()
const db = getWorkspaceDB(client, workspaceId)
const _client = await client.getClient()
const db = getWorkspaceDB(_client, workspaceId)
await db
.collection(DOMAIN_DOC_INDEX_STATE)
.updateMany({ _class: core.class.DocIndexState }, { $set: { elastic: false } })
} finally {
await client.close()
client.close()
}

await dropElastic(elasticUrl, workspaceId)
Expand Down
11 changes: 6 additions & 5 deletions dev/tool/src/markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import core, {
type WorkspaceId,
getCollaborativeDocId
} from '@hcengineering/core'
import { getWorkspaceDB } from '@hcengineering/mongo'
import { getMongoClient, getWorkspaceDB } from '@hcengineering/mongo'
import { type StorageAdapter } from '@hcengineering/server-core'
import { connect } from '@hcengineering/server-tool'
import { jsonToText } from '@hcengineering/text'
import { type Db, MongoClient } from 'mongodb'
import { type Db } from 'mongodb'

export async function fixJsonMarkup (
ctx: MeasureContext,
Expand All @@ -27,8 +27,9 @@ export async function fixJsonMarkup (
})) as unknown as CoreClient
const hierarchy = connection.getHierarchy()

const client = new MongoClient(mongoUrl)
const db = getWorkspaceDB(client, workspaceId)
const client = getMongoClient(mongoUrl)
const _client = await client.getClient()
const db = getWorkspaceDB(_client, workspaceId)

try {
const classes = hierarchy.getDescendants(core.class.Doc)
Expand All @@ -48,7 +49,7 @@ export async function fixJsonMarkup (
await processFixJsonMarkupFor(ctx, domain, _class, filtered, workspaceId, db, storageAdapter)
}
} finally {
await client.close()
client.close()
await connection.close()
}
}
Expand Down
11 changes: 5 additions & 6 deletions dev/tool/src/mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ import core, {
SortingOrder,
type WorkspaceId
} from '@hcengineering/core'
import { getWorkspaceDB } from '@hcengineering/mongo'
import { getMongoClient, getWorkspaceDB } from '@hcengineering/mongo'
import { connect } from '@hcengineering/server-tool'
import { MongoClient } from 'mongodb'

interface PropertyInfo {
name: string
Expand Down Expand Up @@ -100,10 +99,10 @@ export async function fixMixinForeignAttributes (
}

if (result.size > 0) {
const client = new MongoClient(mongoUrl)
const client = getMongoClient(mongoUrl)
try {
await client.connect()
const db = getWorkspaceDB(client, workspaceId)
const _client = await client.getClient()
const db = getWorkspaceDB(_client, workspaceId)

for (const [mixin, objects] of result) {
console.log('fixing', mixin)
Expand Down Expand Up @@ -134,7 +133,7 @@ export async function fixMixinForeignAttributes (
}
}
} finally {
await client.close()
client.close()
}
}
} catch (err: any) {
Expand Down
16 changes: 8 additions & 8 deletions dev/tool/src/telegram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
//

import { DOMAIN_TX, type MeasureContext, type Ref, type WorkspaceId } from '@hcengineering/core'
import { type StorageAdapter } from '@hcengineering/server-core'
import { DOMAIN_ATTACHMENT } from '@hcengineering/model-attachment'
import contact, { DOMAIN_CHANNEL } from '@hcengineering/model-contact'
import { DOMAIN_TELEGRAM } from '@hcengineering/model-telegram'
import { getWorkspaceDB } from '@hcengineering/mongo'
import { getMongoClient, getWorkspaceDB } from '@hcengineering/mongo'
import { type StorageAdapter } from '@hcengineering/server-core'
import telegram, { type SharedTelegramMessage, type SharedTelegramMessages } from '@hcengineering/telegram'
import { type Document, MongoClient, type UpdateFilter } from 'mongodb'
import { type Document, type UpdateFilter } from 'mongodb'

const LastMessages = 'last-msgs'

Expand All @@ -35,11 +35,11 @@ export async function clearTelegramHistory (
tgDb: string,
storageAdapter: StorageAdapter
): Promise<void> {
const client = new MongoClient(mongoUrl)
const client = getMongoClient(mongoUrl)
try {
await client.connect()
const workspaceDB = getWorkspaceDB(client, workspaceId)
const telegramDB = client.db(tgDb)
const _client = await client.getClient()
const workspaceDB = getWorkspaceDB(_client, workspaceId)
const telegramDB = _client.db(tgDb)

const sharedMessages = await workspaceDB
.collection(DOMAIN_TELEGRAM)
Expand Down Expand Up @@ -99,6 +99,6 @@ export async function clearTelegramHistory (
workspace: workspaceId
})
} finally {
await client.close()
client.close()
}
}
39 changes: 19 additions & 20 deletions dev/tool/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@

import contact from '@hcengineering/contact'
import core, {
type Client as CoreClient,
type BackupClient,
type Client as CoreClient,
type Doc,
DOMAIN_DOC_INDEX_STATE,
DOMAIN_TX,
type Tx,
type WorkspaceId,
type Ref,
type Doc,
DOMAIN_DOC_INDEX_STATE
type Tx,
type WorkspaceId
} from '@hcengineering/core'
import { getWorkspaceDB } from '@hcengineering/mongo'
import { MongoClient } from 'mongodb'
import { generateModelDiff, printDiff } from './mdiff'
import { getMongoClient, getWorkspaceDB } from '@hcengineering/mongo'
import { connect } from '@hcengineering/server-tool'
import { generateModelDiff, printDiff } from './mdiff'

export async function diffWorkspace (mongoUrl: string, workspace: WorkspaceId, rawTxes: Tx[]): Promise<void> {
const client = new MongoClient(mongoUrl)
const client = getMongoClient(mongoUrl)
try {
await client.connect()
const db = getWorkspaceDB(client, workspace)
const _client = await client.getClient()
const db = getWorkspaceDB(_client, workspace)

console.log('diffing transactions...')

Expand Down Expand Up @@ -68,7 +67,7 @@ export async function diffWorkspace (mongoUrl: string, workspace: WorkspaceId, r
}
}
} finally {
await client.close()
client.close()
}
}

Expand All @@ -81,18 +80,18 @@ export async function updateField (
const connection = (await connect(transactorUrl, workspaceId, undefined, {
mode: 'backup'
})) as unknown as CoreClient & BackupClient
const client = new MongoClient(mongoUrl)
const client = getMongoClient(mongoUrl)
let valueToPut: string | number = cmd.value
if (cmd.type === 'number') valueToPut = parseFloat(valueToPut)
try {
const _client = await client.getClient()
try {
await client.connect()
const db = getWorkspaceDB(client, workspaceId)
const db = getWorkspaceDB(_client, workspaceId)
await db
.collection(cmd.domain)
.updateOne({ _id: cmd.objectId as Ref<Doc> }, { $set: { [cmd.attribute]: valueToPut } })
} finally {
await client.close()
client.close()
}
} finally {
await connection.close()
Expand All @@ -104,19 +103,19 @@ export async function recreateElastic (
workspaceId: WorkspaceId,
transactorUrl: string
): Promise<void> {
const client = new MongoClient(mongoUrl)
const client = getMongoClient(mongoUrl)
const _client = await client.getClient()
const connection = (await connect(transactorUrl, workspaceId, undefined, {
mode: 'backup'
})) as unknown as CoreClient & BackupClient
try {
await client.connect()
const db = getWorkspaceDB(client, workspaceId)
const db = getWorkspaceDB(_client, workspaceId)
await db
.collection(DOMAIN_DOC_INDEX_STATE)
.updateMany({ _class: core.class.DocIndexState }, { $set: { stages: {} } })
await connection.sendForceClose()
} finally {
await client.close()
client.close()
await connection.close()
}
}
1 change: 1 addition & 0 deletions pods/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_phase:docker-staging": "rushx docker:staging",
"bundle": "mkdir -p bundle && esbuild src/__start.ts --bundle --define:process.env.MODEL_VERSION=$(node ../../common/scripts/show_version.js) --minify --platform=node > bundle/bundle.js",
"docker:build": "../../common/scripts/docker_build.sh hardcoreeng/account",
"docker:tbuild": "docker build -t hardcoreeng/account . --platform=linux/amd64 && ../../common/scripts/docker_tag_push.sh hardcoreeng/account",
haiodo marked this conversation as resolved.
Show resolved Hide resolved
"docker:staging": "../../common/scripts/docker_tag.sh hardcoreeng/account staging",
"docker:push": "../../common/scripts/docker_tag.sh hardcoreeng/account",
"run-local": "cross-env MONGO_URL=mongodb://localhost:27017 MINIO_ACCESS_KEY=minioadmi MINIO_SECRET_KEY=minioadmin MINIO_ENDPOINT=localhost SERVER_SECRET='secret' TRANSACTOR_URL=ws://localhost:3333 ts-node src/__start.ts",
Expand Down
1 change: 1 addition & 0 deletions server/account-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@hcengineering/platform": "^0.6.11",
"@hcengineering/auth-providers": "^0.6.0",
"@hcengineering/core": "^0.6.32",
"@hcengineering/mongo": "^0.6.1",
"mongodb": "^6.8.0",
"koa": "^2.15.3",
"koa-router": "^12.0.1",
Expand Down
Loading