Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for the module column, if it doesn't exist, add it. #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion EMigrateCommand.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;

$db->schema->refresh();
if ($db->schema->getTable($this->migrationTable)===null)
{
echo 'Creating migration history table "'.$this->migrationTable.'"...';
Expand All @@ -378,6 +378,15 @@ protected function getMigrationHistory($limit)
));
echo "done.\n";
}
elseif (!in_array('module', array_keys($db->schema->getTable($this->migrationTable)->columns)))
{
// 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) {
$select = "version AS version_name, apply_time";
Expand Down
7 changes: 1 addition & 6 deletions readme.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down