mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -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",
|
"chai-as-promised": "^7.1.1",
|
||||||
"mocha": "^10.2.0",
|
"mocha": "^10.2.0",
|
||||||
"mock-fs": "^5.2.0",
|
"mock-fs": "^5.2.0",
|
||||||
"mongodb": "^6.1.0",
|
"mongodb": "6.7.0",
|
||||||
"sandboxed-module": "^2.0.4",
|
"sandboxed-module": "^2.0.4",
|
||||||
"sinon": "^9.2.4",
|
"sinon": "^9.2.4",
|
||||||
"sinon-chai": "^3.7.0",
|
"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",
|
"body-parser": "^1.20.3",
|
||||||
"exegesis-express": "^4.0.0",
|
"exegesis-express": "^4.0.0",
|
||||||
"express": "^4.21.0",
|
"express": "^4.21.0",
|
||||||
"mongodb": "^6.1.0"
|
"mongodb": "6.7.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acorn": "^7.1.1",
|
"acorn": "^7.1.1",
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
"body-parser": "^1.20.3",
|
"body-parser": "^1.20.3",
|
||||||
"bunyan": "^1.8.15",
|
"bunyan": "^1.8.15",
|
||||||
"express": "^4.21.0",
|
"express": "^4.21.0",
|
||||||
"mongodb": "^6.1.0",
|
"mongodb": "6.7.0",
|
||||||
"request": "~2.88.2",
|
"request": "~2.88.2",
|
||||||
"underscore": "~1.13.1"
|
"underscore": "~1.13.1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
"celebrate": "^15.0.3",
|
"celebrate": "^15.0.3",
|
||||||
"express": "^4.21.0",
|
"express": "^4.21.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"mongodb-legacy": "^6.0.1",
|
"mongodb-legacy": "6.1.0",
|
||||||
"p-map": "^4.0.0",
|
"p-map": "^4.0.0",
|
||||||
"request": "^2.88.2"
|
"request": "^2.88.2"
|
||||||
},
|
},
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
"express": "^4.21.0",
|
"express": "^4.21.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"minimist": "^1.2.8",
|
"minimist": "^1.2.8",
|
||||||
"mongodb-legacy": "^6.0.1",
|
"mongodb-legacy": "6.1.0",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"requestretry": "^7.1.0"
|
"requestretry": "^7.1.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
"chai": "^4.3.6",
|
"chai": "^4.3.6",
|
||||||
"chai-as-promised": "^7.1.1",
|
"chai-as-promised": "^7.1.1",
|
||||||
"mocha": "^10.2.0",
|
"mocha": "^10.2.0",
|
||||||
"mongodb": "^6.1.0",
|
"mongodb": "6.7.0",
|
||||||
"sandboxed-module": "2.0.4",
|
"sandboxed-module": "2.0.4",
|
||||||
"sinon": "9.0.2",
|
"sinon": "9.0.2",
|
||||||
"sinon-chai": "^3.7.0",
|
"sinon-chai": "^3.7.0",
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
"jsonwebtoken": "^9.0.0",
|
"jsonwebtoken": "^9.0.0",
|
||||||
"knex": "^2.4.0",
|
"knex": "^2.4.0",
|
||||||
"lodash": "^4.17.19",
|
"lodash": "^4.17.19",
|
||||||
"mongodb": "^6.2.0",
|
"mongodb": "6.7.0",
|
||||||
"overleaf-editor-core": "*",
|
"overleaf-editor-core": "*",
|
||||||
"pg": "^8.7.1",
|
"pg": "^8.7.1",
|
||||||
"swagger-tools": "^0.10.4",
|
"swagger-tools": "^0.10.4",
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
"bunyan": "^1.8.15",
|
"bunyan": "^1.8.15",
|
||||||
"express": "^4.21.0",
|
"express": "^4.21.0",
|
||||||
"method-override": "^3.0.0",
|
"method-override": "^3.0.0",
|
||||||
"mongodb-legacy": "^6.0.1",
|
"mongodb-legacy": "6.1.0",
|
||||||
"request": "^2.88.2"
|
"request": "^2.88.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
"esmock": "^2.6.3",
|
"esmock": "^2.6.3",
|
||||||
"express": "^4.21.0",
|
"express": "^4.21.0",
|
||||||
"lodash": "^4.17.20",
|
"lodash": "^4.17.20",
|
||||||
"mongodb-legacy": "^6.0.1",
|
"mongodb-legacy": "6.1.0",
|
||||||
"overleaf-editor-core": "*",
|
"overleaf-editor-core": "*",
|
||||||
"request": "^2.88.2"
|
"request": "^2.88.2"
|
||||||
},
|
},
|
||||||
|
|
|
@ -61,18 +61,6 @@ mongoose.plugin(schema => {
|
||||||
|
|
||||||
mongoose.Promise = global.Promise
|
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
|
mongoose.connectionPromise = connectionPromise
|
||||||
|
|
||||||
module.exports = mongoose
|
module.exports = mongoose
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Helpers from './lib/helpers.mjs'
|
import Helpers from './lib/helpers.mjs'
|
||||||
|
import { getCollectionInternal } from '../app/src/infrastructure/mongodb.js'
|
||||||
|
|
||||||
const tags = ['server-ce', 'server-pro', 'saas']
|
const tags = ['server-ce', 'server-pro', 'saas']
|
||||||
|
|
||||||
|
@ -12,13 +13,13 @@ const indexes = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const migrate = async ({ nativeDb }) => {
|
const migrate = async () => {
|
||||||
const docOps = nativeDb.collection('docOps')
|
const docOps = await getCollectionInternal('docOps')
|
||||||
await Helpers.addIndexesToCollection(docOps, indexes)
|
await Helpers.addIndexesToCollection(docOps, indexes)
|
||||||
}
|
}
|
||||||
|
|
||||||
const rollback = async ({ nativeDb }) => {
|
const rollback = async () => {
|
||||||
const docOps = nativeDb.collection('docOps')
|
const docOps = await getCollectionInternal('docOps')
|
||||||
await Helpers.dropIndexesFromCollection(docOps, indexes)
|
await Helpers.dropIndexesFromCollection(docOps, indexes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import mongodbLegacy from 'mongodb-legacy'
|
import mongodbLegacy from 'mongodb-legacy'
|
||||||
|
import { db, getCollectionInternal } from '../app/src/infrastructure/mongodb.js'
|
||||||
const { ObjectId, ReadPreference } = mongodbLegacy
|
const { ObjectId, ReadPreference } = mongodbLegacy
|
||||||
|
|
||||||
const BATCH_SIZE = parseInt(process.env.BATCH_SIZE || '1000', 10)
|
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 tags = ['server-ce', 'server-pro', 'saas']
|
||||||
|
|
||||||
const migrate = async ({ db, nativeDb }) => {
|
const migrate = async () => {
|
||||||
const docOps = nativeDb.collection('docOps')
|
const docOps = await getCollectionInternal('docOps')
|
||||||
|
|
||||||
const filter = {}
|
const filter = {}
|
||||||
if (MIN_ID) {
|
if (MIN_ID) {
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
import Path from 'path'
|
import Path from 'path'
|
||||||
import mongodb from '../../app/src/infrastructure/mongodb.js'
|
import { db } from '../../app/src/infrastructure/mongodb.js'
|
||||||
import Mongoose from '../../app/src/infrastructure/Mongoose.js'
|
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url)
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
const __dirname = Path.dirname(__filename)
|
const __dirname = Path.dirname(__filename)
|
||||||
const { db } = mongodb
|
|
||||||
const { getNativeDb } = Mongoose
|
|
||||||
|
|
||||||
class Adapter {
|
class Adapter {
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
|
@ -26,8 +23,7 @@ class Adapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
const nativeDb = await getNativeDb()
|
return { db }
|
||||||
return { db, nativeDb }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
|
@ -35,7 +31,6 @@ class Adapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getExecutedMigrationNames() {
|
async getExecutedMigrationNames() {
|
||||||
const { db } = await this.connect()
|
|
||||||
const migrations = await db.migrations
|
const migrations = await db.migrations
|
||||||
.find({}, { sort: { migratedAt: 1 }, projection: { name: 1 } })
|
.find({}, { sort: { migratedAt: 1 }, projection: { name: 1 } })
|
||||||
.toArray()
|
.toArray()
|
||||||
|
@ -43,7 +38,6 @@ class Adapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
async markExecuted(name) {
|
async markExecuted(name) {
|
||||||
const { db } = await this.connect()
|
|
||||||
return db.migrations.insertOne({
|
return db.migrations.insertOne({
|
||||||
name,
|
name,
|
||||||
migratedAt: new Date(),
|
migratedAt: new Date(),
|
||||||
|
@ -51,7 +45,6 @@ class Adapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
async unmarkExecuted(name) {
|
async unmarkExecuted(name) {
|
||||||
const { db } = await this.connect()
|
|
||||||
return db.migrations.deleteOne({
|
return db.migrations.deleteOne({
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,8 +6,18 @@ import {
|
||||||
getCollectionInternal,
|
getCollectionInternal,
|
||||||
} from '../../app/src/infrastructure/mongodb.js'
|
} 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) {
|
async function addIndexesToCollection(collection, indexes) {
|
||||||
return Promise.all(
|
await Promise.all(
|
||||||
indexes.map(index => {
|
indexes.map(index => {
|
||||||
index.background = true
|
index.background = true
|
||||||
return collection.createIndex(index.key, index)
|
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) {
|
async function dropIndexesFromCollection(collection, indexes) {
|
||||||
return Promise.all(
|
await Promise.all(
|
||||||
indexes.map(async index => {
|
indexes.map(async index => {
|
||||||
try {
|
try {
|
||||||
await collection.dropIndex(index.name)
|
await collection.dropIndex(index.name)
|
||||||
|
@ -31,6 +46,10 @@ async function dropIndexesFromCollection(collection, indexes) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} collectionName
|
||||||
|
* @return {Promise<void>}
|
||||||
|
*/
|
||||||
async function dropCollection(collectionName) {
|
async function dropCollection(collectionName) {
|
||||||
if (db[collectionName]) {
|
if (db[collectionName]) {
|
||||||
throw new Error(`blocking drop of an active collection: ${collectionName}`)
|
throw new Error(`blocking drop of an active collection: ${collectionName}`)
|
||||||
|
|
|
@ -3,30 +3,29 @@ const {
|
||||||
connectionPromise,
|
connectionPromise,
|
||||||
db,
|
db,
|
||||||
} = require('../../../app/src/infrastructure/mongodb')
|
} = require('../../../app/src/infrastructure/mongodb')
|
||||||
const { getMongoClient } = require('../../../app/src/infrastructure/Mongoose')
|
|
||||||
|
|
||||||
const MIN_MONGO_VERSION = [5, 0]
|
const MIN_MONGO_VERSION = [5, 0]
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
let mongoClient
|
||||||
try {
|
try {
|
||||||
await connectionPromise
|
mongoClient = await connectionPromise
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Cannot connect to mongodb')
|
console.error('Cannot connect to mongodb')
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
|
|
||||||
await checkMongoVersion()
|
await checkMongoVersion(mongoClient)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await testTransactions()
|
await testTransactions(mongoClient)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Mongo instance doesn't support transactions")
|
console.error("Mongo instance doesn't support transactions")
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testTransactions() {
|
async function testTransactions(mongoClient) {
|
||||||
const mongoClient = await getMongoClient()
|
|
||||||
const session = mongoClient.startSession()
|
const session = mongoClient.startSession()
|
||||||
try {
|
try {
|
||||||
await session.withTransaction(async () => {
|
await session.withTransaction(async () => {
|
||||||
|
@ -37,8 +36,7 @@ async function testTransactions() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkMongoVersion() {
|
async function checkMongoVersion(mongoClient) {
|
||||||
const mongoClient = await getMongoClient()
|
|
||||||
const buildInfo = await mongoClient.db().admin().buildInfo()
|
const buildInfo = await mongoClient.db().admin().buildInfo()
|
||||||
const [major, minor] = buildInfo.versionArray
|
const [major, minor] = buildInfo.versionArray
|
||||||
const [minMajor, minMinor] = MIN_MONGO_VERSION
|
const [minMajor, minMinor] = MIN_MONGO_VERSION
|
||||||
|
|
Loading…
Reference in a new issue