You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
const path = require('path')
|
|
|
|
const fs = require('fs-extra')
|
|
|
|
const semver = require('semver')
|
|
|
|
|
|
|
|
const baseMigrationPath = path.join(WIKI.SERVERPATH, 'db/migrations')
|
|
|
|
|
|
|
|
/* global WIKI */
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
/**
|
|
|
|
* Gets the migration names
|
|
|
|
* @returns Promise<string[]>
|
|
|
|
*/
|
|
|
|
async getMigrations() {
|
|
|
|
const migrationFiles = await fs.readdir(baseMigrationPath)
|
|
|
|
return migrationFiles.map(m => m.replace('.js', '')).sort(semver.compare).map(m => ({
|
|
|
|
file: m,
|
|
|
|
directory: baseMigrationPath
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
|
|
|
|
getMigrationName(migration) {
|
|
|
|
return migration.file.indexOf('.js') >= 0 ? migration.file : `${migration.file}.js`
|
|
|
|
},
|
|
|
|
|
|
|
|
getMigration(migration) {
|
|
|
|
return require(path.join(baseMigrationPath, migration.file))
|
|
|
|
}
|
|
|
|
}
|