From 0070b978371b998f15792f21cfbe1a1f8f17e75b Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 12 Jul 2017 11:48:03 +0200 Subject: [PATCH] allow migrate/mark to mark the history base (#14428) fixes #7890 --- framework/CHANGELOG.md | 1 + framework/console/controllers/BaseMigrateController.php | 8 ++++++-- .../console/controllers/MigrateControllerTestTrait.php | 12 ++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index d2314b6..c5bb671 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.13 under development ------------------------ +- Bug #7890: Allow `migrate/mark` to mark history at the point of the base migration (cebe) - Chg #14321: `yii\widgets\MaskedInput` is now registering its JavaScript `clientOptions` initialization code in head section (DaveFerger) - Bug #13757: Fixed ambiguous column error in `BaseActiveRecord::refresh()` when the query adds a JOIN by default (cebe, ivankff) - Bug #14248: `yii\console\controllers\MessageController` no longer outputs colorized filenames when console does not support text colorization (PowerGamer1) diff --git a/framework/console/controllers/BaseMigrateController.php b/framework/console/controllers/BaseMigrateController.php index 15577fe..3687255 100644 --- a/framework/console/controllers/BaseMigrateController.php +++ b/framework/console/controllers/BaseMigrateController.php @@ -366,11 +366,14 @@ abstract class BaseMigrateController extends Controller * ``` * yii migrate/mark 101129_185401 # using timestamp * yii migrate/mark m101129_185401_create_user_table # using full name - * yii migrate/to app\migrations\M101129185401CreateUser # using full namespace name + * yii migrate/mark app\migrations\M101129185401CreateUser # using full namespace name + * yii migrate/mark m000000_000000_base # reset the complete migration history * ``` * * @param string $version the version at which the migration history should be marked. * This can be either the timestamp or the full name of the migration. + * You may specify the name `m000000_000000_base` to set the migration history to a + * state where no migration has been applied. * @return int CLI exit code * @throws Exception if the version argument is invalid or the version cannot be found. */ @@ -381,7 +384,7 @@ abstract class BaseMigrateController extends Controller $version = $namespaceVersion; } elseif (($migrationName = $this->extractMigrationVersion($version)) !== false) { $version = $migrationName; - } else { + } elseif ($version !== static::BASE_MIGRATION) { throw new Exception("The version argument must be either a timestamp (e.g. 101129_185401)\nor the full name of a migration (e.g. m101129_185401_create_user_table)\nor the full name of a namespaced migration (e.g. app\\migrations\\M101129185401CreateUserTable)."); } @@ -402,6 +405,7 @@ abstract class BaseMigrateController extends Controller // try mark down $migrations = array_keys($this->getMigrationHistory(null)); + $migrations[] = static::BASE_MIGRATION; foreach ($migrations as $i => $migration) { if (strpos($migration, $version) === 0) { if ($i === 0) { diff --git a/tests/framework/console/controllers/MigrateControllerTestTrait.php b/tests/framework/console/controllers/MigrateControllerTestTrait.php index b95160f..8fe97a8 100644 --- a/tests/framework/console/controllers/MigrateControllerTestTrait.php +++ b/tests/framework/console/controllers/MigrateControllerTestTrait.php @@ -312,6 +312,18 @@ CODE; $this->assertMigrationHistory(['m*_base', 'm*_test_mark1']); } + public function testMarkBase() + { + $version = '010101_000001'; + $this->createMigration('test_mark1', $version); + + $this->runMigrateControllerAction('up'); + $this->assertMigrationHistory(['m*_base', 'm*_test_mark1']); + + $this->runMigrateControllerAction('mark', [BaseMigrateController::BASE_MIGRATION]); + $this->assertMigrationHistory(['m*_base']); + } + public function testTo() { $version = '020202_000001';