Skip to content

Commit 71ed0d9

Browse files
committed
Update RunMigrationsCommand.php
1 parent 44d0675 commit 71ed0d9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

webfiori/framework/cli/commands/RunMigrationsCommand.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,22 @@ public function exec() : int {
139139
$this->error($ex->getMessage());
140140
return -1;
141141
}
142-
return $this->executeMigrations($runner);
142+
if ($this->isArgProvided("--rollback")) {
143+
return $this->rollbackMigration($runner);
144+
} else {
145+
return $this->executeMigrations($runner);
146+
}
147+
}
148+
private function rollbackMigration(MigrationsRunner $runner) {
149+
$this->println("Rolling back last executed migration...");
150+
$migration = $runner->rollback();
151+
152+
if ($migration !== null) {
153+
$this->success("Migration '".$migration->getName()."' was successfully rolled back.");
154+
} else {
155+
$this->info("No migration rolled back.");
156+
}
157+
return 0;
143158
}
144159
private function executeMigrations(MigrationsRunner $runner) {
145160
$this->println("Starting to execute migrations...");

0 commit comments

Comments
 (0)