UNPKG

@magic-mustard/sqlsync

Version:

SQLSync simplifies database schema evolution by allowing a declarative approach to table management

56 lines (55 loc) 2.04 kB
"use strict"; // cli/undo.ts var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.UndoCommand = void 0; const chalk_1 = __importDefault(require("chalk")); const inquirer_1 = __importDefault(require("inquirer")); class UndoCommand { register(program) { program .command('undo [migration-name]') .description('Undo (roll back) to a specific migration (inclusive)') .option('--delete-files', 'Delete the migration files after rolling back') .action((migrationName, options) => { const undoOpts = { migrationName, deleteFiles: !!options.deleteFiles, }; this.handleUndo(undoOpts); }); } handleUndo(opts) { if (!opts.migrationName) { console.log(chalk_1.default.red('Error: A migration name is required for "undo".')); process.exit(1); } inquirer_1.default .prompt([ { type: 'confirm', name: 'confirmUndo', message: chalk_1.default.yellow(`Are you sure you want to undo migration "${opts.migrationName}"? (Destructive)`), default: false, }, ]) .then((answer) => { if (!answer.confirmUndo) { console.log('Undo canceled.'); return; } console.log(chalk_1.default.magenta(`(Stub) Undoing migration: ${opts.migrationName}`)); if (opts.deleteFiles) { console.log(chalk_1.default.magenta('(Stub) Deleting migration files.')); // Synchronous file deletion if needed } }) .catch((err) => { console.error(chalk_1.default.red('Prompt error:'), err); process.exit(1); }); } } exports.UndoCommand = UndoCommand;