Fixes #16278: Fixed drop existing views when console migrate/fresh command runs

This commit is contained in:
Elvira Sheina
2018-06-30 04:19:40 +05:00
committed by Alexander Makarov
parent 77d7a5046e
commit e55b3e0ba1
3 changed files with 16 additions and 2 deletions

View File

@ -26,6 +26,7 @@ Yii Framework 2 Change Log
- Bug #14636: Views can now use relative paths even when using themed views (sammousa) - Bug #14636: Views can now use relative paths even when using themed views (sammousa)
- Bug #16245: Fixed `__isset()` in `BaseActiveRecord` not catching errors (sammousa) - Bug #16245: Fixed `__isset()` in `BaseActiveRecord` not catching errors (sammousa)
- Bug #16266: Fixed `yii\helpers\BaseStringHelper` where explode would not allow 0 as trim string (Thoulah) - Bug #16266: Fixed `yii\helpers\BaseStringHelper` where explode would not allow 0 as trim string (Thoulah)
- Bug #16278: Fixed drop existing views when console `migrate/fresh` command runs (developeruz)
- Bug #16277: Fixed `yii\db\Query::from()` to respect `yii\db\ExpressionInterface` (noname007) - Bug #16277: Fixed `yii\db\Query::from()` to respect `yii\db\ExpressionInterface` (noname007)
- Bug #16280: Fixed `yii\base\Model::getActiveValidators()` to return correct validators for attribute on scenario (paweljankowiak06) - Bug #16280: Fixed `yii\base\Model::getActiveValidators()` to return correct validators for attribute on scenario (paweljankowiak06)
- Enh #16191: Enhanced `yii\helpers\Inflector` to work correctly with UTF-8 (silverfire) - Enh #16191: Enhanced `yii\helpers\Inflector` to work correctly with UTF-8 (silverfire)

View File

@ -310,8 +310,17 @@ class MigrateController extends BaseMigrateController
// Then drop the tables: // Then drop the tables:
foreach ($schemas as $schema) { foreach ($schemas as $schema) {
$db->createCommand()->dropTable($schema->name)->execute(); try {
$this->stdout("Table {$schema->name} dropped.\n"); $db->createCommand()->dropTable($schema->name)->execute();
$this->stdout("Table {$schema->name} dropped.\n");
} catch (\Exception $e) {
if (strpos($e->getMessage(), 'DROP VIEW to delete view') !== false) {
$db->createCommand()->dropView($schema->name)->execute();
$this->stdout("View {$schema->name} dropped.\n");
} else {
$this->stdout("Cannot drop {$schema->name} Table .\n");
}
}
} }
} }

View File

@ -287,10 +287,14 @@ class MigrateControllerTest extends TestCase
Yii::$app->db->createCommand("insert into hall_of_fame values(2, 'Alexander Makarov');") Yii::$app->db->createCommand("insert into hall_of_fame values(2, 'Alexander Makarov');")
->execute(); ->execute();
Yii::$app->db->createCommand('create view view_hall_of_fame as select * from hall_of_fame')
->execute();
$result = $this->runMigrateControllerAction('fresh'); $result = $this->runMigrateControllerAction('fresh');
// Drop worked // Drop worked
$this->assertContains('Table hall_of_fame dropped.', $result); $this->assertContains('Table hall_of_fame dropped.', $result);
$this->assertContains('View view_hall_of_fame dropped.', $result);
// Migration was restarted // Migration was restarted
$this->assertContains('No new migrations found. Your system is up-to-date.', $result); $this->assertContains('No new migrations found. Your system is up-to-date.', $result);