Commit bb1a964c by Klimov Paul

Fixed multiple entries of base migration in history for MongoDB

parent 5f852465
......@@ -122,6 +122,8 @@ class MigrateController extends BaseMigrateController
*/
protected function getMigrationHistory($limit)
{
$this->ensureBaseMigrationHistory();
$query = new Query;
$rows = $query->select(['version', 'apply_time'])
->from($this->migrationCollection)
......@@ -129,15 +131,33 @@ class MigrateController extends BaseMigrateController
->limit($limit)
->all($this->db);
$history = ArrayHelper::map($rows, 'version', 'apply_time');
if (empty($history)) {
$this->addMigrationHistory(self::BASE_MIGRATION);
}
unset($history[self::BASE_MIGRATION]);
return $history;
}
/**
* Ensures migration history contains at least base migration entry.
*/
protected function ensureBaseMigrationHistory()
{
static $ensured = false;
if (!$ensured) {
$query = new Query;
$row = $query->select(['version'])
->from($this->migrationCollection)
->andWhere(['version' => self::BASE_MIGRATION])
->limit(1)
->one($this->db);
if (empty($row)) {
$this->addMigrationHistory(self::BASE_MIGRATION);
}
$ensured = true;
}
}
/**
* @inheritdoc
*/
protected function addMigrationHistory($version)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment