Skip to content

Commit

Permalink
Merge pull request #35 from stevebauman/fix-truncate
Browse files Browse the repository at this point in the history
Use `delete()` instead of `truncate()` in Migration Repository
  • Loading branch information
babenkoivan authored Jan 16, 2022
2 parents 3e7f050 + 6afbcb5 commit cddfd32
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Console/FreshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function handle(

$indexManager->drop('*');

$migrationRepository->truncate();
$migrationRepository->deleteAll();

$migrator->migrateAll();

Expand Down
8 changes: 8 additions & 0 deletions src/Repositories/MigrationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public function delete(string $fileName): bool
->delete();
}

public function deleteAll(): void
{
$this->table()->delete();
}

/**
* @deprecated
*/
public function truncate(): void
{
$this->table()->truncate();
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Console/FreshCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function test_does_nothing_if_migrator_is_not_ready(): void

$this->migrationRepository
->expects($this->never())
->method('truncate');
->method('deleteAll');

$this->migrator
->expects($this->never())
Expand Down Expand Up @@ -91,7 +91,7 @@ public function test_drops_indicies_and_migration(): void

$this->migrationRepository
->expects($this->once())
->method('truncate');
->method('deleteAll');

$this->migrator
->expects($this->once())
Expand Down
9 changes: 9 additions & 0 deletions tests/Integration/Repositories/MigrationRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,13 @@ public function test_repository_is_not_ready_when_table_does_not_exist(): void

$this->assertFalse($this->migrationRepository->isReady());
}

public function test_repository_can_delete_all_records(): void
{
$this->assertCount(2, $this->migrationRepository->getAll());

$this->migrationRepository->deleteAll();

$this->assertCount(0, $this->migrationRepository->getAll());
}
}

0 comments on commit cddfd32

Please sign in to comment.