Merge pull request #21442 from overleaf/jpa-align-mongo-version

[misc] align all the mongodb dependency versions

GitOrigin-RevId: 1194fe57601af98bb61250a285bfc85b4b8179dd
This commit is contained in:
Jakob Ackermann
2024-11-01 09:05:23 +00:00
committed by Copybot
parent f9300a4595
commit fa95775a5c
16 changed files with 511 additions and 1440 deletions
@@ -1,4 +1,5 @@
import Helpers from './lib/helpers.mjs'
import { getCollectionInternal } from '../app/src/infrastructure/mongodb.js'
const tags = ['server-ce', 'server-pro', 'saas']
@@ -12,13 +13,13 @@ const indexes = [
},
]
const migrate = async ({ nativeDb }) => {
const docOps = nativeDb.collection('docOps')
const migrate = async () => {
const docOps = await getCollectionInternal('docOps')
await Helpers.addIndexesToCollection(docOps, indexes)
}
const rollback = async ({ nativeDb }) => {
const docOps = nativeDb.collection('docOps')
const rollback = async () => {
const docOps = await getCollectionInternal('docOps')
await Helpers.dropIndexesFromCollection(docOps, indexes)
}
@@ -1,4 +1,5 @@
import mongodbLegacy from 'mongodb-legacy'
import { db, getCollectionInternal } from '../app/src/infrastructure/mongodb.js'
const { ObjectId, ReadPreference } = mongodbLegacy
const BATCH_SIZE = parseInt(process.env.BATCH_SIZE || '1000', 10)
@@ -6,8 +7,8 @@ const MIN_ID = process.env.MIN_ID
const tags = ['server-ce', 'server-pro', 'saas']
const migrate = async ({ db, nativeDb }) => {
const docOps = nativeDb.collection('docOps')
const migrate = async () => {
const docOps = await getCollectionInternal('docOps')
const filter = {}
if (MIN_ID) {
+2 -9
View File
@@ -1,12 +1,9 @@
import Path from 'path'
import mongodb from '../../app/src/infrastructure/mongodb.js'
import Mongoose from '../../app/src/infrastructure/Mongoose.js'
import { db } from '../../app/src/infrastructure/mongodb.js'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = Path.dirname(__filename)
const { db } = mongodb
const { getNativeDb } = Mongoose
class Adapter {
constructor(params) {
@@ -26,8 +23,7 @@ class Adapter {
}
async connect() {
const nativeDb = await getNativeDb()
return { db, nativeDb }
return { db }
}
disconnect() {
@@ -35,7 +31,6 @@ class Adapter {
}
async getExecutedMigrationNames() {
const { db } = await this.connect()
const migrations = await db.migrations
.find({}, { sort: { migratedAt: 1 }, projection: { name: 1 } })
.toArray()
@@ -43,7 +38,6 @@ class Adapter {
}
async markExecuted(name) {
const { db } = await this.connect()
return db.migrations.insertOne({
name,
migratedAt: new Date(),
@@ -51,7 +45,6 @@ class Adapter {
}
async unmarkExecuted(name) {
const { db } = await this.connect()
return db.migrations.deleteOne({
name,
})
+21 -2
View File
@@ -6,8 +6,18 @@ import {
getCollectionInternal,
} from '../../app/src/infrastructure/mongodb.js'
/**
* @typedef {import('mongodb-legacy').Document} Collection
* @typedef {import('mongodb-legacy').Collection<Document>} Collection
*/
/**
* @param {Collection} collection
* @param {Array<{ name: string }>} indexes
* @return {Promise<void>}
*/
async function addIndexesToCollection(collection, indexes) {
return Promise.all(
await Promise.all(
indexes.map(index => {
index.background = true
return collection.createIndex(index.key, index)
@@ -15,8 +25,13 @@ async function addIndexesToCollection(collection, indexes) {
)
}
/**
* @param {Collection} collection
* @param {Array<{ name: string }>} indexes
* @return {Promise<void>}
*/
async function dropIndexesFromCollection(collection, indexes) {
return Promise.all(
await Promise.all(
indexes.map(async index => {
try {
await collection.dropIndex(index.name)
@@ -31,6 +46,10 @@ async function dropIndexesFromCollection(collection, indexes) {
)
}
/**
* @param {string} collectionName
* @return {Promise<void>}
*/
async function dropCollection(collectionName) {
if (db[collectionName]) {
throw new Error(`blocking drop of an active collection: ${collectionName}`)