Skip to content

Commit f6c05c9

Browse files
committed
Merge branch '4.next' into 4.x
2 parents c7312f2 + 6e64e7d commit f6c05c9

29 files changed

Lines changed: 1170 additions & 1254 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- 3.x
77
- 4.x
8+
- 4.next
89
pull_request:
910
branches:
1011
- '*'
@@ -27,7 +28,7 @@ jobs:
2728
- php-version: '8.1'
2829
db-type: 'sqlite'
2930
prefer-lowest: 'prefer-lowest'
30-
- php-version: '8.2'
31+
- php-version: '8.3'
3132
db-type: 'mysql'
3233
- php-version: '8.3'
3334
db-type: 'pgsql'

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
},
2424
"require": {
2525
"php": ">=8.1",
26-
"cakephp/cache": "^5.0",
27-
"cakephp/orm": "^5.0",
26+
"cakephp/cache": "^5.2",
27+
"cakephp/orm": "^5.2",
2828
"robmorgan/phinx": "^0.16.10"
2929
},
3030
"require-dev": {
31-
"cakephp/bake": "^3.0",
32-
"cakephp/cakephp": "^5.0.11",
31+
"cakephp/bake": "^3.3",
32+
"cakephp/cakephp": "^5.2.5",
3333
"cakephp/cakephp-codesniffer": "^5.0",
3434
"phpunit/phpunit": "^10.5.5 || ^11.1.3 || ^12.2.4"
3535
},

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,6 @@ parameters:
150150
count: 1
151151
path: src/Db/Adapter/SqlserverAdapter.php
152152

153-
-
154-
message: '#^Ternary operator condition is always true\.$#'
155-
identifier: ternary.alwaysTrue
156-
count: 2
157-
path: src/Db/Adapter/SqlserverAdapter.php
158-
159153
-
160154
message: '#^Call to an undefined method Migrations\\Db\\Table\\Index\:\:setUnique\(\)\.$#'
161155
identifier: method.notFound

src/CakeManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function printStatus(string $environment, ?string $format = null): array
7171
$migrations = [];
7272
$isJson = $format === 'json';
7373
$defaultMigrations = $this->getMigrations('default');
74-
if (count($defaultMigrations)) {
74+
if ($defaultMigrations) {
7575
$env = $this->getEnvironment($environment);
7676
$versions = $env->getVersionLog();
7777
$this->maxNameLength = $versions ? max(array_map(function ($version) {

src/Command/DumpCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
135135
}
136136

137137
$filePath = $path . DS . 'schema-dump-' . $connectionName . '.lock';
138-
$io->out("<info>Writing dump file `{$filePath}`...</info>");
138+
$io->verbose("<info>Writing dump file `{$filePath}`...</info>");
139139
if (file_put_contents($filePath, serialize($dump))) {
140-
$io->out("<info>Dump file `{$filePath}` was successfully written</info>");
140+
$io->verbose("<info>Dump file `{$filePath}` was successfully written</info>");
141141

142142
return self::CODE_SUCCESS;
143143
}
144-
$io->out("<error>An error occurred while writing dump file `{$filePath}`</error>");
144+
$io->error("An error occurred while writing dump file `{$filePath}`");
145145

146146
return self::CODE_ERROR;
147147
}

src/Command/MigrateCommand.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Cake\Event\EventDispatcherTrait;
2121
use DateTime;
2222
use Exception;
23+
use LogicException;
2324
use Migrations\Config\ConfigInterface;
2425
use Migrations\Migration\ManagerFactory;
2526
use Throwable;
@@ -125,29 +126,36 @@ protected function executeMigrations(Arguments $args, ConsoleIo $io): ?int
125126
$version = $args->getOption('target') !== null ? (int)$args->getOption('target') : null;
126127
$date = $args->getOption('date');
127128
$fake = (bool)$args->getOption('fake');
128-
$dryRun = (bool)$args->getOption('dry-run');
129129

130-
$count = $args->getOption('count');
131-
if ($count) {
132-
$io->abort('The `--count` option is not supported yet in this command. Use `--target` instead.');
130+
$count = $args->getOption('count') !== null ? (int)$args->getOption('count') : null;
131+
if ($count !== null && $count < 1) {
132+
throw new LogicException('Count must be > 0.');
133+
}
134+
if ($count && $date) {
135+
throw new LogicException('Can only use one of `--count` or `--date` options at a time.');
136+
}
137+
if ($version && $date) {
138+
throw new LogicException('Can only use one of `--version` or `--date` options at a time.');
133139
}
134140

135141
$factory = new ManagerFactory([
136142
'plugin' => $args->getOption('plugin'),
137143
'source' => $args->getOption('source'),
138144
'connection' => $args->getOption('connection'),
139-
'dry-run' => $dryRun,
145+
'dry-run' => (bool)$args->getOption('dry-run'),
140146
]);
147+
141148
$manager = $factory->createManager($io);
142149
$config = $manager->getConfig();
143150

144151
$versionOrder = $config->getVersionOrder();
145-
if ($dryRun) {
146-
$io->out('<warning>dry-run mode enabled</warning>');
152+
153+
if ($config->isDryRun()) {
154+
$io->info('DRY-RUN mode enabled');
147155
}
148-
$io->out('<info>using connection</info> ' . (string)$args->getOption('connection'));
149-
$io->out('<info>using paths</info> ' . $config->getMigrationPath());
150-
$io->out('<info>ordering by</info> ' . $versionOrder . ' time');
156+
$io->verbose('<info>using connection</info> ' . (string)$args->getOption('connection'));
157+
$io->verbose('<info>using paths</info> ' . $config->getMigrationPath());
158+
$io->verbose('<info>ordering by</info> ' . $versionOrder . ' time');
151159

152160
if ($fake) {
153161
$io->out('<warning>warning</warning> performing fake migrations');
@@ -159,31 +167,31 @@ protected function executeMigrations(Arguments $args, ConsoleIo $io): ?int
159167
if ($date !== null) {
160168
$manager->migrateToDateTime(new DateTime((string)$date), $fake);
161169
} else {
162-
$manager->migrate($version, $fake);
170+
$manager->migrate($version, $fake, $count);
163171
}
164172
$end = microtime(true);
165173
} catch (Exception $e) {
166174
$io->err('<error>' . $e->getMessage() . '</error>');
167-
$io->out($e->getTraceAsString(), 1, ConsoleIo::VERBOSE);
175+
$io->verbose($e->getTraceAsString());
168176

169177
return self::CODE_ERROR;
170178
} catch (Throwable $e) {
171179
$io->err('<error>' . $e->getMessage() . '</error>');
172-
$io->out($e->getTraceAsString(), 1, ConsoleIo::VERBOSE);
180+
$io->verbose($e->getTraceAsString());
173181

174182
return self::CODE_ERROR;
175183
}
176184

185+
$io->comment('All Done. Took ' . sprintf('%.4fs', $end - $start));
177186
$io->out('');
178-
$io->out('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');
179187

180188
$exitCode = self::CODE_SUCCESS;
181189

182190
// Run dump command to generate lock file
183191
if (!$args->getOption('no-lock') && !$args->getOption('dry-run')) {
184-
$io->out('');
185-
$io->out('Dumping the current schema of the database to be used while baking a diff');
186-
$io->out('');
192+
$io->verbose('');
193+
$io->verbose('Dumping the current schema of the database to be used while baking a diff');
194+
$io->verbose('');
187195

188196
$newArgs = DumpCommand::extractArgs($args);
189197
$exitCode = $this->executeCommand(DumpCommand::class, $newArgs, $io);

src/Command/RollbackCommand.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use DateTime;
2222
use Exception;
2323
use InvalidArgumentException;
24+
use LogicException;
2425
use Migrations\Config\ConfigInterface;
2526
use Migrations\Migration\ManagerFactory;
2627
use Throwable;
@@ -77,6 +78,9 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
7778
])->addOption('date', [
7879
'short' => 'd',
7980
'help' => 'The date to rollback to',
81+
])->addOption('count', [
82+
'short' => 'k',
83+
'help' => 'The number of migrations to rollback',
8084
])->addOption('fake', [
8185
'help' => "Mark any migrations selected as run, but don't actually execute them",
8286
'boolean' => true,
@@ -130,6 +134,17 @@ protected function executeMigrations(Arguments $args, ConsoleIo $io): ?int
130134
$force = (bool)$args->getOption('force');
131135
$dryRun = (bool)$args->getOption('dry-run');
132136

137+
$count = $args->getOption('count') !== null ? (int)$args->getOption('count') : null;
138+
if ($count !== null && $count < 1) {
139+
throw new LogicException('Count must be > 0.');
140+
}
141+
if ($count && $date) {
142+
throw new LogicException('Can only use one of `--count` or `--date` options at a time.');
143+
}
144+
if ($version && $date) {
145+
throw new LogicException('Can only use one of `--version` or `--date` options at a time.');
146+
}
147+
133148
$factory = new ManagerFactory([
134149
'plugin' => $args->getOption('plugin'),
135150
'source' => $args->getOption('source'),
@@ -140,12 +155,12 @@ protected function executeMigrations(Arguments $args, ConsoleIo $io): ?int
140155
$config = $manager->getConfig();
141156

142157
$versionOrder = $config->getVersionOrder();
143-
$io->out('<info>using connection</info> ' . (string)$args->getOption('connection'));
144-
$io->out('<info>using paths</info> ' . $config->getMigrationPath());
145-
$io->out('<info>ordering by</info> ' . $versionOrder . ' time');
158+
$io->verbose('<info>using connection</info> ' . (string)$args->getOption('connection'));
159+
$io->verbose('<info>using paths</info> ' . $config->getMigrationPath());
160+
$io->verbose('<info>ordering by</info> ' . $versionOrder . ' time');
146161

147162
if ($dryRun) {
148-
$io->out('<warning>dry-run mode enabled</warning>');
163+
$io->info('DRY-RUN mode enabled');
149164
}
150165
if ($fake) {
151166
$io->out('<warning>warning</warning> performing fake rollbacks');
@@ -162,30 +177,34 @@ protected function executeMigrations(Arguments $args, ConsoleIo $io): ?int
162177
try {
163178
// run the migrations
164179
$start = microtime(true);
165-
$manager->rollback($target, $force, $targetMustMatch, $fake);
180+
if ($count) {
181+
$manager->rollbackByCount($count, $force, $fake);
182+
} else {
183+
$manager->rollback($target, $force, $targetMustMatch, $fake);
184+
}
166185
$end = microtime(true);
167186
} catch (Exception $e) {
168187
$io->err('<error>' . $e->getMessage() . '</error>');
169-
$io->out($e->getTraceAsString(), 1, ConsoleIo::VERBOSE);
188+
$io->verbose($e->getTraceAsString());
170189

171190
return self::CODE_ERROR;
172191
} catch (Throwable $e) {
173192
$io->err('<error>' . $e->getMessage() . '</error>');
174-
$io->out($e->getTraceAsString(), 1, ConsoleIo::VERBOSE);
193+
$io->verbose($e->getTraceAsString());
175194

176195
return self::CODE_ERROR;
177196
}
178197

198+
$io->comment('All Done. Took ' . sprintf('%.4fs', $end - $start));
179199
$io->out('');
180-
$io->out('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');
181200

182201
$exitCode = self::CODE_SUCCESS;
183202

184203
// Run dump command to generate lock file
185204
if (!$args->getOption('no-lock')) {
186-
$io->out('');
187-
$io->out('Dumping the current schema of the database to be used while baking a diff');
188-
$io->out('');
205+
$io->verbose('');
206+
$io->verbose('Dumping the current schema of the database to be used while baking a diff');
207+
$io->verbose('');
189208

190209
$newArgs = DumpCommand::extractArgs($args);
191210
$exitCode = $this->executeCommand(DumpCommand::class, $newArgs, $io);

src/Command/SeedCommand.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
6565
'short' => 'c',
6666
'help' => 'The datasource connection to use',
6767
'default' => 'default',
68+
])->addOption('dry-run', [
69+
'short' => 'x',
70+
'help' => 'Dump queries to stdout instead of executing them',
71+
'boolean' => true,
6872
])->addOption('source', [
6973
'short' => 's',
7074
'default' => ConfigInterface::DEFAULT_SEED_FOLDER,
@@ -109,19 +113,26 @@ protected function executeSeeds(Arguments $args, ConsoleIo $io): ?int
109113
'plugin' => $args->getOption('plugin'),
110114
'source' => $args->getOption('source'),
111115
'connection' => $args->getOption('connection'),
116+
'dry-run' => (bool)$args->getOption('dry-run'),
112117
]);
118+
113119
$manager = $factory->createManager($io);
114120
$config = $manager->getConfig();
121+
115122
if (version_compare(Configure::version(), '5.2.0', '>=')) {
116123
$seeds = (array)$args->getArrayOption('seed');
117124
} else {
118125
$seeds = (array)$args->getMultipleOption('seed');
119126
}
120127

121128
$versionOrder = $config->getVersionOrder();
122-
$io->out('<info>using connection</info> ' . (string)$args->getOption('connection'));
123-
$io->out('<info>using paths</info> ' . $config->getMigrationPath());
124-
$io->out('<info>ordering by</info> ' . $versionOrder . ' time');
129+
130+
if ($config->isDryRun()) {
131+
$io->info('DRY-RUN mode enabled');
132+
}
133+
$io->verbose('<info>using connection</info> ' . (string)$args->getOption('connection'));
134+
$io->verbose('<info>using paths</info> ' . $config->getMigrationPath());
135+
$io->verbose('<info>ordering by</info> ' . $versionOrder . ' time');
125136

126137
$start = microtime(true);
127138
if (!$seeds) {
@@ -135,7 +146,7 @@ protected function executeSeeds(Arguments $args, ConsoleIo $io): ?int
135146
}
136147
$end = microtime(true);
137148

138-
$io->out('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');
149+
$io->comment('All Done. Took ' . sprintf('%.4fs', $end - $start));
139150

140151
return self::CODE_SUCCESS;
141152
}

src/Config/Config.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ public function isVersionOrderCreationTime(): bool
178178
return $versionOrder == self::VERSION_ORDER_CREATION_TIME;
179179
}
180180

181+
/**
182+
* @inheritdoc
183+
*/
184+
public function isDryRun(): bool
185+
{
186+
return $this->values['environment']['dryrun'] ?? false;
187+
}
188+
181189
/**
182190
* {@inheritDoc}
183191
*

src/Config/ConfigInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,11 @@ public function getSeedBaseClassName(bool $dropNamespace = true): string;
108108
* @return string|null
109109
*/
110110
public function getSeedTemplateFile(): ?string;
111+
112+
/**
113+
* Should queries be sent to the database or just print to stdout?
114+
*
115+
* @return bool
116+
*/
117+
public function isDryRun(): bool;
111118
}

0 commit comments

Comments
 (0)