Skip to content

Commit e6753fc

Browse files
joe-titoJoe Titocrynobone
authored
Handle case when migrate:install command is called and table exists (#54938)
* Handle case when migrate:install command is called when migrations table already exists * Fixing tests * Formatting * Delete package-lock.json --------- Co-authored-by: Joe Tito <[email protected]> Co-authored-by: Mior Muhammad Zaki <[email protected]>
1 parent 7ddf5ae commit e6753fc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Illuminate/Database/Console/Migrations/InstallCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public function handle()
5353
{
5454
$this->repository->setSource($this->input->getOption('database'));
5555

56-
$this->repository->createRepository();
56+
if (! $this->repository->repositoryExists()) {
57+
$this->repository->createRepository();
58+
}
5759

5860
$this->components->info('Migration table created successfully.');
5961
}

tests/Database/DatabaseMigrationInstallCommandTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ public function testFireCallsRepositoryToInstall()
2323
$command->setLaravel(new Application);
2424
$repo->shouldReceive('setSource')->once()->with('foo');
2525
$repo->shouldReceive('createRepository')->once();
26+
$repo->shouldReceive('repositoryExists')->once()->andReturn(false);
27+
28+
$this->runCommand($command, ['--database' => 'foo']);
29+
}
30+
31+
public function testFireCallsRepositoryToInstallExists()
32+
{
33+
$command = new InstallCommand($repo = m::mock(MigrationRepositoryInterface::class));
34+
$command->setLaravel(new Application);
35+
$repo->shouldReceive('setSource')->once()->with('foo');
36+
$repo->shouldReceive('repositoryExists')->once()->andReturn(true);
2637

2738
$this->runCommand($command, ['--database' => 'foo']);
2839
}

0 commit comments

Comments
 (0)