diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 41e0e62..e6f209f 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -243,6 +243,7 @@ Yii Framework 2 Change Log - Enh #3283: Added `$checkAjax` to `yii\web\User::loginRequired()` (qiangxue) - Enh #3284: Added support for checking multiple ETags by `yii\filters\HttpCache` (qiangxue) - Enh #3298: Supported configuring `View::theme` using a class name (netyum, qiangxue) +- Enh #3305: `yii migrate` now automatically flushes DB schema cache after successful migration (6pblcb, samdark) - Enh #3328: `BaseMailer` generates better text body from html body (armab) - Enh #3380: Allow `value` in `defaultValueValidator` to be a closure (Alex-Code) - Enh #3384: Added callback-style transactions (leandrogehlen, Ragazzo, samdark) diff --git a/framework/console/controllers/BaseMigrateController.php b/framework/console/controllers/BaseMigrateController.php index 82a1ee5..a9cd418 100644 --- a/framework/console/controllers/BaseMigrateController.php +++ b/framework/console/controllers/BaseMigrateController.php @@ -490,6 +490,7 @@ abstract class BaseMigrateController extends Controller $this->addMigrationHistory($class); $time = microtime(true) - $start; echo "*** applied $class (time: " . sprintf("%.3f", $time) . "s)\n\n"; + $this->refreshSchema(); return true; } else { @@ -519,6 +520,7 @@ abstract class BaseMigrateController extends Controller $time = microtime(true) - $start; echo "*** reverted $class (time: " . sprintf("%.3f", $time) . "s)\n\n"; + return true; } else { $time = microtime(true) - $start; @@ -623,6 +625,16 @@ abstract class BaseMigrateController extends Controller return $migrations; } + + /** + * Flushes DB schema cache. + * This method should be implemented if connection has DB schema support. + * @param string $name connection component name + * @since 2.0.1 + */ + protected function refreshSchema($name = 'db') + { + } /** * Returns the migration history. diff --git a/framework/console/controllers/MigrateController.php b/framework/console/controllers/MigrateController.php index 826bc58..9a11c82 100644 --- a/framework/console/controllers/MigrateController.php +++ b/framework/console/controllers/MigrateController.php @@ -178,4 +178,13 @@ class MigrateController extends BaseMigrateController 'version' => $version, ])->execute(); } + + /** + * @inheritdoc + */ + protected function refreshSchema($name = 'db') + { + $this->db->schema->refresh(); + echo "DB schema cache was flushed.\n"; + } }