Skip to content

Commit 136e139

Browse files
authored
Merge pull request cakephp#1375 from markkimsal/features/warn_when_ignoring_up_down
Warn when up or down will be ignored
2 parents 5649fd1 + ce2c0f7 commit 136e139

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/Phinx/Migration/AbstractMigration.php

+21
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,25 @@ public function dropTable($tableName)
326326
trigger_error('dropTable() is deprecated since 0.10.0. Use $this->table($tableName)->drop()->save() instead.', E_USER_DEPRECATED);
327327
$this->table($tableName)->drop()->save();
328328
}
329+
330+
/**
331+
* Perform checks on the migration, print a warning
332+
* if there are potential problems.
333+
*
334+
* Right now, the only check is if there is both a `change()` and
335+
* an `up()` or a `down()` method.
336+
*
337+
* @return void
338+
*/
339+
public function preFlightCheck()
340+
{
341+
if (method_exists($this, MigrationInterface::CHANGE)) {
342+
if (method_exists($this, MigrationInterface::UP) ||
343+
method_exists($this, MigrationInterface::DOWN) ) {
344+
$this->output->writeln(sprintf(
345+
'<comment>warning</comment> Migration contains both change() and/or up()/down() methods. <options=bold>Ignoring up() and down()</>.'
346+
));
347+
}
348+
}
349+
}
329350
}

src/Phinx/Migration/Manager.php

+1
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ public function executeMigration($name, MigrationInterface $migration, $directio
380380
' <info>' . $migration->getVersion() . ' ' . $migration->getName() . ':</info>' .
381381
' <comment>' . ($direction === MigrationInterface::UP ? 'migrating' : 'reverting') . '</comment>'
382382
);
383+
$migration->preFlightCheck();
383384

384385
// Execute the migration and log the time elapsed.
385386
$start = microtime(true);

src/Phinx/Migration/MigrationInterface.php

+8
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,12 @@ public function hasTable($tableName);
248248
* @return \Phinx\Db\Table
249249
*/
250250
public function table($tableName, $options);
251+
252+
/**
253+
* Perform checks on the migration, print a warning
254+
* if there are potential problems.
255+
*
256+
* @return void
257+
*/
258+
public function preFlightCheck();
251259
}

0 commit comments

Comments
 (0)