Skip to content

Commit

Permalink
[5.3] Fix for migrate:rollback with FETCH_ASSOC enabled (#15081) (#15088
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mcfdn authored and taylorotwell committed Aug 27, 2016
1 parent e3ed514 commit c57afd8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Illuminate/Database/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,12 @@ public function rollback($paths = [], array $options = [])
$this->requireFiles($files);

foreach ($migrations as $migration) {
$migration = (object) $migration;
$rolledBack[] = $files[$migration->migration];

$this->runDown(
$files[$migration->migration],
(object) $migration, Arr::get($options, 'pretend', false)
$migration, Arr::get($options, 'pretend', false)
);
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Database/DatabaseMigratorIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ public function testMigrationsCanBeRolledBack()
$this->assertTrue(str_contains($rolledBack[1], 'users'));
}

public function testMigrationsCanBeRolledBackWithFetchAssocEnabled()
{
$this->db->getConnection()->setFetchMode(\PDO::FETCH_ASSOC);

$this->migrator->run([__DIR__.'/migrations/one']);
$this->assertTrue($this->db->schema()->hasTable('users'));
$this->assertTrue($this->db->schema()->hasTable('password_resets'));
$rolledBack = $this->migrator->rollback([__DIR__.'/migrations/one']);
$this->assertFalse($this->db->schema()->hasTable('users'));
$this->assertFalse($this->db->schema()->hasTable('password_resets'));

$this->assertTrue(str_contains($rolledBack[0], 'password_resets'));
$this->assertTrue(str_contains($rolledBack[1], 'users'));
}

public function testMigrationsCanBeReset()
{
$this->migrator->run([__DIR__.'/migrations/one']);
Expand Down

0 comments on commit c57afd8

Please sign in to comment.