overleaf/services/web/migrations/lib/adapter.js
Alexandre Bourdin 07e5d1ba90 Merge pull request #5229 from overleaf/ab-splittest-name-index
Add migration to create unique index on splittests name

GitOrigin-RevId: d7420ad714a09abedafb7462b51b3c403c9a026b
2021-10-01 08:03:19 +00:00

61 lines
1.3 KiB
JavaScript

const Path = require('path')
const {
addCollection,
waitForDb,
db,
} = require('../../app/src/infrastructure/mongodb')
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.js')
}
async connect() {
await waitForDb()
await addCollection('projectImportFailures')
await addCollection('samllog')
await addCollection('user')
await addCollection('splittests')
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: name,
migratedAt: new Date(),
})
}
async unmarkExecuted(name) {
return db.migrations.deleteOne({
name: name,
})
}
}
module.exports = Adapter