Permalink
Browse files

added customization of 'migrations' subdirectory

you can now set $migrationSubPath to customize the
subdirectory used for migrations, when yii module config
is used.

this is related to issue #12
  • Loading branch information...
1 parent 75848ce commit 8bcb3713d775c83b872bd224655c4fbd2f966ab4 @cebe cebe committed Feb 17, 2012
Showing with 30 additions and 7 deletions.
  1. +1 −1 EDbMigration.php
  2. +21 −6 EMigrateCommand.php
  3. +4 −0 changelog.txt
  4. +2 −0 readme_en.txt
  5. +2 −0 readme_ru.txt
View
2 EDbMigration.php
@@ -6,7 +6,7 @@
* @link http://www.yiiframework.com/extension/extended-database-migration/
* @link http://www.yiiframework.com/doc/guide/1.1/en/database.migration
* @author Carsten Brandt <mail@cebe.cc>
- * @version 0.7.1
+ * @version 0.8.0-dev
*/
class EDbMigration extends CDbMigration
{
View
27 EMigrateCommand.php
@@ -17,7 +17,7 @@
* @link http://www.yiiframework.com/extension/extended-database-migration/
* @link http://www.yiiframework.com/doc/guide/1.1/en/database.migration
* @author Carsten Brandt <mail@cebe.cc>
- * @version 0.7.1
+ * @version 0.8.0-dev
*/
Yii::import('system.cli.commands.MigrateCommand');
@@ -55,6 +55,12 @@ class EMigrateCommand extends MigrateCommand
public $moduleDelimiter = ': ';
/**
+ * @var string subdirectory to use for migrations in Yii alias format
+ * this is only used if you do not set modulePath explicitly {@see setModulePaths()}
+ */
+ public $migrationSubPath = 'migrations';
+
+ /**
* @var array|null list of all modules
* @see getModulePaths()
* @see setModulePaths()
@@ -78,11 +84,19 @@ public function getModulePaths()
$this->_modulePaths = array();
foreach(Yii::app()->modules as $module => $config) {
if (is_array($config)) {
- $alias = 'application.modules.' . $module . '.migrations';
+ $alias = 'application.modules.' . $module . '.' . ltrim($this->migrationSubPath, '.');
if (isset($config['class'])) {
- Yii::setPathOfAlias($alias, dirname(Yii::getPathOfAlias($config['class'])) . '/migrations');
+ Yii::setPathOfAlias(
+ $alias,
+ dirname(Yii::getPathOfAlias($config['class'])) . '/' .
+ str_replace('.', '/', ltrim($this->migrationSubPath, '.'))
+ );
} elseif (isset($config['basePath'])) {
- Yii::setPathOfAlias($alias, $config['basePath'] . '/migrations');
+ Yii::setPathOfAlias(
+ $alias,
+ $config['basePath'] . '/' .
+ str_replace('.', '/', ltrim($this->migrationSubPath, '.'))
+ );
}
$this->_modulePaths[$module] = $alias;
$path = Yii::getPathOfAlias($alias);
@@ -91,7 +105,7 @@ public function getModulePaths()
}
} else {
- $this->_modulePaths[$config] = 'application.modules.' . $config . '.migrations';
+ $this->_modulePaths[$config] = 'application.modules.' . $config . '.' . ltrim($this->migrationSubPath, '.');
}
}
}
@@ -109,8 +123,9 @@ public function getModulePaths()
* If set to null, which is default, yii applications module config will be used
* If modules are taken from yii application config, all entries will be
* 'moduleName' => 'application.modules.<moduleName>.migrations',
+ * You can change the subpath name by setting {@see migrationSubPath} which is 'migrations' per default.
* If 'class' or 'basePath' are set in module config the above path alias is
- * set to class/basePath with {@see Yii::setPathOfAlias()}.
+ * adjusted to class/basePath with {@see Yii::setPathOfAlias()}.
*
* example:
* array(
View
4 changelog.txt
@@ -1,6 +1,10 @@
Changelog
---------
+#### 0.8.0 (to be released)
+
+- Enh: #12 added customization of 'migrations' subdirectory via $migrationSubPath (cebe thanks to redguy666)
+
#### 0.7.1 (2012-01-31)
- fix for getTable trying to hit a db cache and die in endless loop (cebe)
View
2 readme_en.txt
@@ -56,6 +56,8 @@ Installation
'yourModule' => 'application.any.other.path.possible',
// ...
),
+ // you can customize the modules migrations subdirectory which is used when you are using yii module config
+ 'migrationSubPath' => 'migrations',
// here you can configure which modules should be active, you can disable a module by adding its name to this array
'disabledModules' => array(
'admin', 'anOtherModule', // ...
View
2 readme_ru.txt
@@ -55,6 +55,8 @@ Extended Migration Command
'yourModule' => 'application.any.other.path.possible',
// ...
),
+ // you can customize the modules migrations subdirectory which is used when you are using yii module config
+ 'migrationSubPath' => 'migrations',
// отключаем некоторые модули
@cebe
cebe Feb 17, 2012

@samdark can you give me a translation? I'm afraid google will not do it as good as you can do it and I still had no time to improve my skills...
thanks in advance!

@samdark
samdark Feb 17, 2012

To be honest, I don't understand English variant :)

@cebe
cebe Feb 17, 2012

Well, with this option you can customize the subdirectory that is used for migration files.
If you have application.modules.mymodule as modules base path content of $migrationSubPath is appended to it.
This will happen when migration command relies on Yii::app()->modules for configuration.
hope this is clearer :-)
Might need to expand that documentation and describe things more detailed since it has grown very big until now...

@samdark
samdark Feb 17, 2012

OK. Then:

можно задать имя поддиректории для хранения миграций в директории модуля

'disabledModules' => array(
'admin', 'anOtherModule', // ...

0 comments on commit 8bcb371

Please sign in to comment.