2021-07-21 10:34:09 +00:00
|
|
|
const Path = require('path')
|
2022-01-10 11:36:18 +00:00
|
|
|
const { waitForDb, db } = require('../../app/src/infrastructure/mongodb')
|
2021-07-21 10:34:09 +00:00
|
|
|
|
|
|
|
class Adapter {
|
|
|
|
constructor(params) {
|
2021-08-04 09:34:41 +00:00
|
|
|
if (
|
|
|
|
!process.env.SKIP_TAG_CHECK &&
|
|
|
|
!process.argv.includes('create') &&
|
|
|
|
!(process.argv.includes('-t') || process.argv.includes('--tags'))
|
|
|
|
) {
|
2021-07-21 10:34:09 +00:00
|
|
|
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()
|
|
|
|
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({
|
2022-05-16 14:25:49 +00:00
|
|
|
name,
|
2021-07-21 10:34:09 +00:00
|
|
|
migratedAt: new Date(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async unmarkExecuted(name) {
|
|
|
|
return db.migrations.deleteOne({
|
2022-05-16 14:25:49 +00:00
|
|
|
name,
|
2021-07-21 10:34:09 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Adapter
|