2024-11-04 04:09:11 -05:00
|
|
|
import Path from 'node:path'
|
2024-10-31 08:19:53 -04:00
|
|
|
import { db } from '../../app/src/infrastructure/mongodb.js'
|
2024-11-04 04:09:11 -05:00
|
|
|
import { fileURLToPath } from 'node:url'
|
2024-10-02 05:32:13 -04:00
|
|
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url)
|
|
|
|
const __dirname = Path.dirname(__filename)
|
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() {
|
2024-10-02 05:32:13 -04:00
|
|
|
return Path.resolve(__dirname, 'template.mjs')
|
2021-07-21 06:34:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async connect() {
|
2024-10-31 08:19:53 -04:00
|
|
|
return { db }
|
2021-07-21 06:34:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-02 05:32:13 -04:00
|
|
|
export default Adapter
|