Skip to content

Commit 29b1e5c

Browse files
committed
Replace readiness checks with preparation
1 parent 6cd1ff2 commit 29b1e5c

19 files changed

Lines changed: 80 additions & 180 deletions

src/Console/FreshCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public function handle(
3636
): int {
3737
$migrator->setOutput($this->output);
3838

39-
if (! $this->confirmToProceed() || ! $migrator->isReady()) {
39+
if (! $this->confirmToProceed()) {
4040
return 1;
4141
}
4242

43+
$migrator->prepare();
44+
4345
$index->drop('*');
4446

4547
$migrations->deleteAll();

src/Console/MigrateCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public function handle(Migrator $migrator): int
3636
{
3737
$migrator->setOutput($this->output);
3838

39-
if (! $this->confirmToProceed() || ! $migrator->isReady()) {
39+
if (! $this->confirmToProceed()) {
4040
return 1;
4141
}
4242

43+
$migrator->prepare();
44+
4345
if ($fileName = $this->argument('fileName')) {
4446
$migrator->migrateOne($fileName);
4547
} else {

src/Console/RefreshCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ public function handle(Migrator $migrator): int
3535
{
3636
$migrator->setOutput($this->output);
3737

38-
if (! $this->confirmToProceed() || ! $migrator->isReady()) {
38+
if (! $this->confirmToProceed()) {
3939
return 1;
4040
}
4141

42+
$migrator->prepare();
43+
4244
$migrator->rollbackAll();
4345
$migrator->migrateAll();
4446

src/Console/ResetCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ public function handle(Migrator $migrator): int
3535
{
3636
$migrator->setOutput($this->output);
3737

38-
if (! $this->confirmToProceed() || ! $migrator->isReady()) {
38+
if (! $this->confirmToProceed()) {
3939
return 1;
4040
}
4141

42+
$migrator->prepare();
43+
4244
$migrator->rollbackAll();
4345

4446
return 0;

src/Console/RollbackCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public function handle(Migrator $migrator): int
3636
{
3737
$migrator->setOutput($this->output);
3838

39-
if (! $this->confirmToProceed() || ! $migrator->isReady()) {
39+
if (! $this->confirmToProceed()) {
4040
return 1;
4141
}
4242

43+
$migrator->prepare();
44+
4345
if ($fileName = $this->argument('fileName')) {
4446
$migrator->rollbackOne($fileName);
4547
} else {

src/Console/StatusCommand.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ public function handle(Migrator $migrator): int
3131
{
3232
$migrator->setOutput($this->output);
3333

34-
if (! $migrator->isReady()) {
35-
return 1;
36-
}
37-
34+
$migrator->prepare();
3835
$migrator->showStatus();
3936

4037
return 0;

src/Filesystem/MigrationStorage.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace DirectoryTree\OpenSearchMigrations\Filesystem;
44

5-
use DirectoryTree\OpenSearchMigrations\ReadinessInterface;
65
use Illuminate\Filesystem\Filesystem;
76
use Illuminate\Support\Collection;
87

98
/**
109
* Stores and retrieves OpenSearch migration files.
1110
*/
12-
class MigrationStorage implements ReadinessInterface
11+
class MigrationStorage
1312
{
1413
/**
1514
* Create a new migration storage instance.
@@ -70,10 +69,10 @@ protected function resolvePath(string $fileName): string
7069
}
7170

7271
/**
73-
* Determine if the migration storage directory exists.
72+
* Prepare the migration storage directory.
7473
*/
75-
public function isReady(): bool
74+
public function prepare(): void
7675
{
77-
return $this->filesystem->isDirectory($this->directory);
76+
$this->filesystem->ensureDirectoryExists($this->directory);
7877
}
7978
}

src/Migrator.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* Runs and rolls back OpenSearch migration files.
1414
*/
15-
class Migrator implements ReadinessInterface
15+
class Migrator
1616
{
1717
/**
1818
* The console output implementation.
@@ -208,18 +208,13 @@ protected function rollback(Collection $fileNames): self
208208
}
209209

210210
/**
211-
* Determine if migrations can be run.
211+
* Prepare the migration repository and storage.
212212
*/
213-
public function isReady(): bool
213+
public function prepare(): self
214214
{
215-
if (! $isMigrationRepositoryReady = $this->migrationRepository->isReady()) {
216-
$this->output->writeln('<error>Migration table is not yet created</error>');
217-
}
218-
219-
if (! $isMigrationStorageReady = $this->migrationStorage->isReady()) {
220-
$this->output->writeln('<error>Migration directory is not yet created</error>');
221-
}
215+
$this->migrationRepository->prepare();
216+
$this->migrationStorage->prepare();
222217

223-
return $isMigrationRepositoryReady && $isMigrationStorageReady;
218+
return $this;
224219
}
225220
}

src/ReadinessInterface.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Repositories/MigrationRepository.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace DirectoryTree\OpenSearchMigrations\Repositories;
44

5-
use DirectoryTree\OpenSearchMigrations\ReadinessInterface;
65
use Illuminate\Database\Query\Builder;
76
use Illuminate\Database\Schema\Blueprint;
87
use Illuminate\Support\Collection;
@@ -13,7 +12,7 @@
1312
/**
1413
* Stores and retrieves executed OpenSearch migration records.
1514
*/
16-
class MigrationRepository implements ReadinessInterface
15+
class MigrationRepository
1716
{
1817
/**
1918
* Create a new migration repository instance.
@@ -132,16 +131,14 @@ protected function table(): Builder
132131
}
133132

134133
/**
135-
* Determine if the migration repository is ready.
134+
* Prepare the migration repository table.
136135
*/
137-
public function isReady(): bool
136+
public function prepare(): void
138137
{
139138
if (Schema::connection($this->connection)->hasTable($this->table)) {
140-
return true;
139+
return;
141140
}
142141

143142
$this->create();
144-
145-
return true;
146143
}
147144
}

0 commit comments

Comments
 (0)