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

30 lines
716 B
JavaScript
Raw 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)
2019-01-26 23:35:56 +00:00
return migrationFiles.sort(semver.compare).map(m => ({
file: m,
2019-02-22 22:05:18 +00:00
directory: baseMigrationPath
2019-01-26 23:35:56 +00:00
}))
},
getMigrationName(migration) {
return migration.file;
},
getMigration(migration) {
2019-02-22 22:05:18 +00:00
return require(path.join(baseMigrationPath, migration.file));
2019-01-26 23:35:56 +00:00
}
}