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