From 6434fbabdfe393c440d36e3fc4f0029093e49d39 Mon Sep 17 00:00:00 2001 From: Josh Priestly Date: Thu, 8 Nov 2012 12:42:38 +0000 Subject: [PATCH 1/2] Add check for the module column, if it doesn't exist, add it. --- EMigrateCommand.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/EMigrateCommand.php b/EMigrateCommand.php index 02db472..9d95e43 100644 --- a/EMigrateCommand.php +++ b/EMigrateCommand.php @@ -367,7 +367,7 @@ protected function getMigrationHistory($limit) // avoid getTable trying to hit a db cache and die in endless loop $db->schemaCachingDuration = 0; Yii::app()->coreMessages->cacheID = false; - + $this->getDbConnection()->schema->refresh(); if ($db->schema->getTable($this->migrationTable)===null) { echo 'Creating migration history table "'.$this->migrationTable.'"...'; @@ -378,6 +378,12 @@ protected function getMigrationHistory($limit) )); echo "done.\n"; } + elseif (!in_array('module', array_keys($this->getDbConnection()->schema->getTable($this->migrationTable)->columns))) + { + $this->getDbConnection()->createCommand( + $this->getDbConnection()->schema->addColumn($this->migrationTable, 'module', 'string') + )->execute(); + } if ($this->_scopeNewMigrations || !$this->_scopeAddModule) { $select = "version AS version_name, apply_time"; From a81bbba6e9afec8657a7c270fbd1997cb1f6814a Mon Sep 17 00:00:00 2001 From: Josh Priestly Date: Thu, 8 Nov 2012 12:52:40 +0000 Subject: [PATCH 2/2] Update existing migrations to "core" and update README --- EMigrateCommand.php | 11 +++++++---- readme.md | 7 +------ 2 files changed, 8 insertions(+), 10 deletions(-) mode change 100644 => 100755 EMigrateCommand.php mode change 100644 => 100755 readme.md diff --git a/EMigrateCommand.php b/EMigrateCommand.php old mode 100644 new mode 100755 index 9d95e43..b2ae776 --- a/EMigrateCommand.php +++ b/EMigrateCommand.php @@ -367,7 +367,7 @@ protected function getMigrationHistory($limit) // avoid getTable trying to hit a db cache and die in endless loop $db->schemaCachingDuration = 0; Yii::app()->coreMessages->cacheID = false; - $this->getDbConnection()->schema->refresh(); + $db->schema->refresh(); if ($db->schema->getTable($this->migrationTable)===null) { echo 'Creating migration history table "'.$this->migrationTable.'"...'; @@ -378,11 +378,14 @@ protected function getMigrationHistory($limit) )); echo "done.\n"; } - elseif (!in_array('module', array_keys($this->getDbConnection()->schema->getTable($this->migrationTable)->columns))) + elseif (!in_array('module', array_keys($db->schema->getTable($this->migrationTable)->columns))) { - $this->getDbConnection()->createCommand( - $this->getDbConnection()->schema->addColumn($this->migrationTable, 'module', 'string') + // add module column + $db->createCommand( + $db->schema->addColumn($this->migrationTable, 'module', 'string') )->execute(); + // update current rows to core migrations + $db->createCommand()->update($this->migrationTable, array('module'=>'core')); } if ($this->_scopeNewMigrations || !$this->_scopeAddModule) { diff --git a/readme.md b/readme.md old mode 100644 new mode 100755 index 2965b4b..a706492 --- a/readme.md +++ b/readme.md @@ -69,12 +69,7 @@ Installation ), ``` -**Please note:** if you already used MigrateCommand before, make sure to add the module column to your migrationTable: - -```sql -ALTER TABLE `tbl_migration` ADD COLUMN `module` varchar(32) DEFAULT NULL; -UPDATE `tbl_migration` SET module='core'; -``` +**Please note:** if you already used MigrateCommand before, the module column will be automatically added Usage -----