From 012513b6a1e90169e9e0e53f7a59841a34fbaeb3 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Mon, 13 Jun 2022 14:15:09 +0200 Subject: [PATCH] feat(medusa-cli): Allow to revert migrations from the CLI (#1353) --- packages/medusa-cli/src/create-cli.js | 4 ++-- packages/medusa/src/commands/migrate.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/medusa-cli/src/create-cli.js b/packages/medusa-cli/src/create-cli.js index 13616de300..c2297f324c 100644 --- a/packages/medusa-cli/src/create-cli.js +++ b/packages/medusa-cli/src/create-cli.js @@ -166,11 +166,11 @@ function buildLocalCommands(cli, isLocalProject) { }) .command({ command: `migrations [action]`, - desc: `Migrate the database to the most recent version.`, + desc: `Manage migrations from the core and your own project`, builder: { action: { demand: true, - choices: ["run", "show"], + choices: ["run", "revert", "show"], }, }, handler: handlerP( diff --git a/packages/medusa/src/commands/migrate.js b/packages/medusa/src/commands/migrate.js index fe95afcf6d..ef51e52048 100644 --- a/packages/medusa/src/commands/migrate.js +++ b/packages/medusa/src/commands/migrate.js @@ -27,6 +27,11 @@ const t = async function({ directory }) { await connection.close() Logger.info("Migrations completed.") process.exit() + } else if (args[0] === "revert") { + await connection.undoLastMigration({ transaction: "all" }) + await connection.close() + Logger.info("Migrations reverted.") + process.exit() } else if (args[0] === "show") { const unapplied = await connection.showMigrations() await connection.close()