wikijs-fork/server/db/migrator-source.js

30 lines
807 B
JavaScript
Raw Permalink Normal View History

2019-01-26 23:35:56 +00:00
const path = require('path')
const fs = require('fs-extra')
const semver = require('semver')
2019-02-22 22:05:18 +00:00
const baseMigrationPath = path.join(WIKI.SERVERPATH, (WIKI.config.db.type !== 'sqlite') ? 'db/migrations' : 'db/migrations-sqlite')
2019-01-26 23:35:56 +00:00
/* global WIKI */
module.exports = {
/**
* Gets the migration names
* @returns Promise<string[]>
*/
async getMigrations() {
2019-02-22 22:05:18 +00:00
const migrationFiles = await fs.readdir(baseMigrationPath)
2020-01-27 02:04:38 +00:00
return migrationFiles.map(m => m.replace('.js', '')).sort(semver.compare).map(m => ({
2019-01-26 23:35:56 +00:00
file: m,
2019-02-22 22:05:18 +00:00
directory: baseMigrationPath
2019-01-26 23:35:56 +00:00
}))
},
getMigrationName(migration) {
2020-01-27 02:04:38 +00:00
return migration.file.indexOf('.js') >= 0 ? migration.file : `${migration.file}.js`
2019-01-26 23:35:56 +00:00
},
getMigration(migration) {
return require(path.join(baseMigrationPath, migration.file))
2019-01-26 23:35:56 +00:00
}
}