mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
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:
parent
0e4c87d131
commit
5bb90dc6cb
16 changed files with 511 additions and 1440 deletions
|
@ -35,7 +35,7 @@
|
|||
"chai-as-promised": "^7.1.1",
|
||||
"mocha": "^10.2.0",
|
||||
"mock-fs": "^5.2.0",
|
||||
"mongodb": "^6.1.0",
|
||||
"mongodb": "6.7.0",
|
||||
"sandboxed-module": "^2.0.4",
|
||||
"sinon": "^9.2.4",
|
||||
"sinon-chai": "^3.7.0",
|
||||
|
|
1855
package-lock.json
generated
1855
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -25,7 +25,7 @@
|
|||
"body-parser": "^1.20.3",
|
||||
"exegesis-express": "^4.0.0",
|
||||
"express": "^4.21.0",
|
||||
"mongodb": "^6.1.0"
|
||||
"mongodb": "6.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"acorn": "^7.1.1",
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
"body-parser": "^1.20.3",
|
||||
"bunyan": "^1.8.15",
|
||||
"express": "^4.21.0",
|
||||
"mongodb": "^6.1.0",
|
||||
"mongodb": "6.7.0",
|
||||
"request": "~2.88.2",
|
||||
"underscore": "~1.13.1"
|
||||
},
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
"celebrate": "^15.0.3",
|
||||
"express": "^4.21.0",
|
||||
"lodash": "^4.17.21",
|
||||
"mongodb-legacy": "^6.0.1",
|
||||
"mongodb-legacy": "6.1.0",
|
||||
"p-map": "^4.0.0",
|
||||
"request": "^2.88.2"
|
||||
},
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
"express": "^4.21.0",
|
||||
"lodash": "^4.17.21",
|
||||
"minimist": "^1.2.8",
|
||||
"mongodb-legacy": "^6.0.1",
|
||||
"mongodb-legacy": "6.1.0",
|
||||
"request": "^2.88.2",
|
||||
"requestretry": "^7.1.0"
|
||||
},
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
"chai": "^4.3.6",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"mocha": "^10.2.0",
|
||||
"mongodb": "^6.1.0",
|
||||
"mongodb": "6.7.0",
|
||||
"sandboxed-module": "2.0.4",
|
||||
"sinon": "9.0.2",
|
||||
"sinon-chai": "^3.7.0",
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
"jsonwebtoken": "^9.0.0",
|
||||
"knex": "^2.4.0",
|
||||
"lodash": "^4.17.19",
|
||||
"mongodb": "^6.2.0",
|
||||
"mongodb": "6.7.0",
|
||||
"overleaf-editor-core": "*",
|
||||
"pg": "^8.7.1",
|
||||
"swagger-tools": "^0.10.4",
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
"bunyan": "^1.8.15",
|
||||
"express": "^4.21.0",
|
||||
"method-override": "^3.0.0",
|
||||
"mongodb-legacy": "^6.0.1",
|
||||
"mongodb-legacy": "6.1.0",
|
||||
"request": "^2.88.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
"esmock": "^2.6.3",
|
||||
"express": "^4.21.0",
|
||||
"lodash": "^4.17.20",
|
||||
"mongodb-legacy": "^6.0.1",
|
||||
"mongodb-legacy": "6.1.0",
|
||||
"overleaf-editor-core": "*",
|
||||
"request": "^2.88.2"
|
||||
},
|
||||
|
|
|
@ -61,18 +61,6 @@ mongoose.plugin(schema => {
|
|||
|
||||
mongoose.Promise = global.Promise
|
||||
|
||||
async function getMongoClient() {
|
||||
const mongooseInstance = await connectionPromise
|
||||
return mongooseInstance.connection.getClient()
|
||||
}
|
||||
|
||||
async function getNativeDb() {
|
||||
const mongooseInstance = await connectionPromise
|
||||
return mongooseInstance.connection.db
|
||||
}
|
||||
|
||||
mongoose.getMongoClient = getMongoClient
|
||||
mongoose.getNativeDb = getNativeDb
|
||||
mongoose.connectionPromise = connectionPromise
|
||||
|
||||
module.exports = mongoose
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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}`)
|
||||
|
|
|
@ -3,30 +3,29 @@ const {
|
|||
connectionPromise,
|
||||
db,
|
||||
} = require('../../../app/src/infrastructure/mongodb')
|
||||
const { getMongoClient } = require('../../../app/src/infrastructure/Mongoose')
|
||||
|
||||
const MIN_MONGO_VERSION = [5, 0]
|
||||
|
||||
async function main() {
|
||||
let mongoClient
|
||||
try {
|
||||
await connectionPromise
|
||||
mongoClient = await connectionPromise
|
||||
} catch (err) {
|
||||
console.error('Cannot connect to mongodb')
|
||||
throw err
|
||||
}
|
||||
|
||||
await checkMongoVersion()
|
||||
await checkMongoVersion(mongoClient)
|
||||
|
||||
try {
|
||||
await testTransactions()
|
||||
await testTransactions(mongoClient)
|
||||
} catch (err) {
|
||||
console.error("Mongo instance doesn't support transactions")
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
async function testTransactions() {
|
||||
const mongoClient = await getMongoClient()
|
||||
async function testTransactions(mongoClient) {
|
||||
const session = mongoClient.startSession()
|
||||
try {
|
||||
await session.withTransaction(async () => {
|
||||
|
@ -37,8 +36,7 @@ async function testTransactions() {
|
|||
}
|
||||
}
|
||||
|
||||
async function checkMongoVersion() {
|
||||
const mongoClient = await getMongoClient()
|
||||
async function checkMongoVersion(mongoClient) {
|
||||
const buildInfo = await mongoClient.db().admin().buildInfo()
|
||||
const [major, minor] = buildInfo.versionArray
|
||||
const [minMajor, minMinor] = MIN_MONGO_VERSION
|
||||
|
|
Loading…
Reference in a new issue