UNPKG

@megaorm/cli

Version:

This package allows you to communicate with MegaORM via commands directly from the command line interface (CLI).

47 lines 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RollbackCommand = void 0; const GeneratorHandler_1 = require("../handlers/GeneratorHandler"); const builder_1 = require("@megaorm/builder"); const MegaCommand_1 = require("../MegaCommand"); const MegaConfig_1 = require("../MegaConfig"); /** * Represents a command to rollback the most recently generated tables. * * The command performs the following actions: * - Resolves the configuration and establishes a connection to the database. * - Identifies the last batch of generated tables. * - Drops the tables created in the most recent generation batch. * * Example Behavior: * - If the first generation created 2 tables, and the second created 4 tables: * - Executing the rollback will drop the last 4 tables created in the second generation. * * This ensures that rollbacks only affect the most recent changes, preserving earlier tables. * * @extends MegaCommand */ class RollbackCommand extends MegaCommand_1.MegaCommand { /** * Executes the rollback command to drop the most recently generated tables. * * The command identifies the last batch of tables created by the most recent * generator files and drops them to revert the changes. * * @returns A promise that resolves when the tables have been successfully dropped * or rejects with an error if the rollback fails. */ static exec() { return new Promise((resolve, reject) => { MegaConfig_1.MegaConfig.load() .then((config) => config.cluster.request(config.default)) .then((con) => Promise.resolve(new builder_1.MegaBuilder(con))) .then((builder) => Promise.resolve(new GeneratorHandler_1.GeneratorHandler(builder))) .then((handler) => handler.rollback()) .then((message) => resolve(this.success(message))) .catch(reject); }); } } exports.RollbackCommand = RollbackCommand; //# sourceMappingURL=RollbackCommand.js.map