Merge pull request #15930 from overleaf/jpa-fix-east-hang

[web] migrations: connect to mongo lazily

GitOrigin-RevId: 565fc6c851bf5493d548330eb2024d418a977779
This commit is contained in:
Jakob Ackermann
2023-11-24 13:03:00 +01:00
committed by Copybot
parent 49d7b220bc
commit d3f299623c

View File

@@ -1,5 +1,4 @@
const Path = require('path')
const { waitForDb, db } = require('../../app/src/infrastructure/mongodb')
class Adapter {
constructor(params) {
@@ -19,6 +18,7 @@ class Adapter {
}
async connect() {
const { waitForDb, db } = require('../../app/src/infrastructure/mongodb')
await waitForDb()
return { db }
}
@@ -28,6 +28,7 @@ class Adapter {
}
async getExecutedMigrationNames() {
const { db } = await this.connect()
const migrations = await db.migrations
.find({}, { sort: { migratedAt: 1 }, projection: { name: 1 } })
.toArray()
@@ -35,6 +36,7 @@ class Adapter {
}
async markExecuted(name) {
const { db } = await this.connect()
return db.migrations.insertOne({
name,
migratedAt: new Date(),
@@ -42,6 +44,7 @@ class Adapter {
}
async unmarkExecuted(name) {
const { db } = await this.connect()
return db.migrations.deleteOne({
name,
})