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.

29 lines
807 B

  1. const path = require('path')
  2. const fs = require('fs-extra')
  3. const semver = require('semver')
  4. const baseMigrationPath = path.join(WIKI.SERVERPATH, (WIKI.config.db.type !== 'sqlite') ? 'db/migrations' : 'db/migrations-sqlite')
  5. /* global WIKI */
  6. module.exports = {
  7. /**
  8. * Gets the migration names
  9. * @returns Promise<string[]>
  10. */
  11. async getMigrations() {
  12. const migrationFiles = await fs.readdir(baseMigrationPath)
  13. return migrationFiles.map(m => m.replace('.js', '')).sort(semver.compare).map(m => ({
  14. file: m,
  15. directory: baseMigrationPath
  16. }))
  17. },
  18. getMigrationName(migration) {
  19. return migration.file.indexOf('.js') >= 0 ? migration.file : `${migration.file}.js`
  20. },
  21. getMigration(migration) {
  22. return require(path.join(baseMigrationPath, migration.file))
  23. }
  24. }