laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

migration:rollback --step=2 does not work

Open ghost opened this issue 4 years ago • 2 comments

  • Laravel-mongodb Version: #.#.#
  • lumen 8 and mongodb 5
  • PHP Version: #.#.#
  • 8.0.8
  • Database Driver & Version:
  • MongoDB extension version | 1.10.0 -- | --

Description:

php artisan migrate:rollback --step=2 or step=1 does not work, it gives 'Nothing to rollback'. But rollback without step works (php artisan migrate:rollback ). Reason is that \Illuminate\Database\Query\Grammars\Grammar::compileOrdersToArray receives array:2 [ "batch" => -1 "migration" => -1 ] and its code treats that array as array of arrays. This is happening with mongodb (github.com/jenssegers/laravel-mongodb) and not with mysql.

Also this returns empty array: \Illuminate\Database\Migrations\Migrator::getMigrationsForRollback that is calling: \Illuminate\Database\Migrations\DatabaseMigrationRepository::getMigrations:

    public function getMigrations($steps)
    {
        $query = $this->table()->where('batch', '>=', '1');

        return $query->orderBy('batch', 'desc')
                     ->orderBy('migration', 'desc')
                     ->take($steps)->get()->all();
    }

Steps to reproduce

  1. create new table migrations
  2. run php artisan migrate
  3. run php artisan migrate:rollback --step=2

obs. make sure the user configured has drop permissions.

Expected behaviour

The migration should take place.

Actual behaviour

Nothing to rollback appears.

Logs: Insert log.txt here (if necessary)

ghost avatar Aug 11 '21 04:08 ghost

Any solution to this ?

akhzarjaved avatar Jul 06 '22 19:07 akhzarjaved

Hi, I am having the same issue, the compileOrdersToArray is being used on multiple places, is there a way to replace this code with a custom function?

Jabirr avatar Aug 04 '22 11:08 Jabirr