Skip to content

Commit

Permalink
fix rollback anonymous migrations (#9)
Browse files Browse the repository at this point in the history
* fix rollback anonymous migrations

* lint

* fix old rollback

Co-authored-by: kirill.osa <kirill.osa@okwork.io>
  • Loading branch information
Kosadchiy and kirill.osa committed Sep 6, 2022
1 parent 8feba79 commit f362c8d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Console/RollbackNewMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Umbrellio\Deploy\Console;

use Illuminate\Console\Command;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -55,10 +56,12 @@ public function handle(): void

private function downMigrationFile(SplFileInfo $f): void
{
require_once $f->getPathname();
$migration = require_once $f;
$filename = explode('.php', $f->getRelativePathname())[0];
$class = Str::studly(implode('_', array_slice(explode('_', $filename), 4)));
$migration = new $class();
if (!$migration instanceof Migration) {
$class = Str::studly(implode('_', array_slice(explode('_', $filename), 4)));
$migration = new $class();
}
if (method_exists($migration, 'down')) {
$migration->down();
DB::table(config('database.migrations', 'migrations'))->where('migration', $filename)->delete();
Expand Down

0 comments on commit f362c8d

Please sign in to comment.