migrate_undo_all.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. var _process = _interopRequireDefault(require("process"));
  3. var _yargs = require("../core/yargs");
  4. var _migrator = require("../core/migrator");
  5. var _helpers = _interopRequireDefault(require("../helpers"));
  6. function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
  7. exports.builder = yargs => (0, _yargs._baseOptions)(yargs).option('to', {
  8. describe: 'Revert to the provided migration',
  9. default: 0,
  10. type: 'string'
  11. }).argv;
  12. exports.handler = async function (args) {
  13. // legacy, gulp used to do this
  14. await _helpers.default.config.init();
  15. await migrationUndoAll(args);
  16. _process.default.exit(0);
  17. };
  18. function migrationUndoAll(args) {
  19. return (0, _migrator.getMigrator)('migration', args).then(migrator => {
  20. return (0, _migrator.ensureCurrentMetaSchema)(migrator).then(() => migrator.executed()).then(migrations => {
  21. if (migrations.length === 0) {
  22. _helpers.default.view.log('No executed migrations found.');
  23. _process.default.exit(0);
  24. }
  25. }).then(() => migrator.down({
  26. to: args.to || 0
  27. }));
  28. }).catch(e => _helpers.default.view.error(e));
  29. }