Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
28 / 28 |
|
100.00% |
19 / 19 |
|
6.15% |
4 / 65 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Plan | |
100.00% |
28 / 28 |
|
100.00% |
19 / 19 |
|
6.15% |
4 / 65 |
|
100.00% |
2 / 2 |
60.90 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| show | |
100.00% |
27 / 27 |
|
100.00% |
18 / 18 |
|
4.69% |
3 / 64 |
|
100.00% |
1 / 1 |
49.43 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celema\Quma\Migrations; |
| 6 | |
| 7 | use Celema\Console\Io; |
| 8 | use Celema\Quma\Environment; |
| 9 | |
| 10 | final readonly class Plan |
| 11 | { |
| 12 | public function __construct( |
| 13 | private Environment $env, |
| 14 | private Planner $planner, |
| 15 | private Log $log, |
| 16 | private Io $io, |
| 17 | ) {} |
| 18 | |
| 19 | /** @param list<string> $migrations */ |
| 20 | public function show(string $namespace, array $migrations, bool $tableExists): int |
| 21 | { |
| 22 | $io = $this->io; |
| 23 | $appliedMigrations = $tableExists ? $this->log->applied($this->env->db) : []; |
| 24 | $pendingMigrations = $this->planner->pendingMigrations( |
| 25 | $namespace, |
| 26 | $migrations, |
| 27 | $appliedMigrations, |
| 28 | ); |
| 29 | $numPending = count($pendingMigrations); |
| 30 | $plural = $numPending > 1 ? 's' : ''; |
| 31 | |
| 32 | $io->echoln("\n<bright-red>Notice</bright-red>: Plan only"); |
| 33 | |
| 34 | if (!$tableExists) { |
| 35 | $io->echoln("Would create migrations table '{$this->env->table}'"); |
| 36 | } |
| 37 | |
| 38 | if ($numPending === 0) { |
| 39 | $io->echoln("\nNo pending migrations"); |
| 40 | } else { |
| 41 | $io->echoln("Would apply {$numPending} migration{$plural}:"); |
| 42 | |
| 43 | foreach ($pendingMigrations as $migration) { |
| 44 | $io->echoln(' - ' . basename($migration)); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | $io->echo("\nNo migrations were executed. "); |
| 49 | |
| 50 | if ($this->env->driver === 'mysql') { |
| 51 | $io->echoln( |
| 52 | 'MySQL migrations are plan-only without --apply because DDL statements can cause implicit commits.', |
| 53 | ); |
| 54 | $io->echoln('Use --apply to run them.'); |
| 55 | } else { |
| 56 | $io->echoln( |
| 57 | 'Use --test-run --yes to execute inside a rollback transaction, or --apply to commit.', |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | } |