overleaf/services/web/migrations/lib/adapter.mjs
Jakob Ackermann 5bb90dc6cb Merge pull request #21442 from overleaf/jpa-align-mongo-version
[misc] align all the mongodb dependency versions

GitOrigin-RevId: 1194fe57601af98bb61250a285bfc85b4b8179dd
2024-11-01 09:05:23 +00:00

54 lines
1.2 KiB
JavaScript

import Path from 'path'
import { db } from '../../app/src/infrastructure/mongodb.js'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = Path.dirname(__filename)
class Adapter {
constructor(params) {
if (
!process.env.SKIP_TAG_CHECK &&
!process.argv.includes('create') &&
!(process.argv.includes('-t') || process.argv.includes('--tags'))
) {
console.error("ERROR: must pass tags using '-t' or '--tags', exiting")
process.exit(1)
}
this.params = params || {}
}
getTemplatePath() {
return Path.resolve(__dirname, 'template.mjs')
}
async connect() {
return { db }
}
disconnect() {
return Promise.resolve()
}
async getExecutedMigrationNames() {
const migrations = await db.migrations
.find({}, { sort: { migratedAt: 1 }, projection: { name: 1 } })
.toArray()
return migrations.map(migration => migration.name)
}
async markExecuted(name) {
return db.migrations.insertOne({
name,
migratedAt: new Date(),
})
}
async unmarkExecuted(name) {
return db.migrations.deleteOne({
name,
})
}
}
export default Adapter