wikijs-fork/server/db/migrator-source.js
rbtprograms 0f9ddf1e5d fix: Switch converted to Object Literal (#940)
* updating a switch into object literal and fixed a couple linter errors

* added a comment about weird formatting

* style: use lodash get

* fix: pass eslint + puglint + jest
2019-08-04 16:31:13 -04:00

30 lines
714 B
JavaScript

const path = require('path')
const fs = require('fs-extra')
const semver = require('semver')
const baseMigrationPath = path.join(WIKI.SERVERPATH, (WIKI.config.db.type !== 'sqlite') ? 'db/migrations' : 'db/migrations-sqlite')
/* global WIKI */
module.exports = {
/**
* Gets the migration names
* @returns Promise<string[]>
*/
async getMigrations() {
const migrationFiles = await fs.readdir(baseMigrationPath)
return migrationFiles.sort(semver.compare).map(m => ({
file: m,
directory: baseMigrationPath
}))
},
getMigrationName(migration) {
return migration.file
},
getMigration(migration) {
return require(path.join(baseMigrationPath, migration.file))
}
}