yiiext/migrate-command

这是Yii数据库迁移工具的增强版本,增加了模块支持和许多其他实用功能。

安装次数: 158,770

依赖者: 9

建议者: 1

安全性: 0

星标: 35

关注者: 9

分支: 17

开放性问题: 13

类型:yii-extension

0.8.0 2014-12-01 16:44 UTC

This package is auto-updated.

Last update: 2024-09-05 18:24:04 UTC


README

本扩展是Yii数据库迁移工具的增强版本,增加了模块支持以及许多其他实用功能。如果您希望添加任何功能或发现任何错误,请通过GitHub或通过电子邮件与我联系。

功能

  • 模块支持(迁移分布在每个模块的单独文件夹中),因此您可以...
  • ...启用和禁用模块
  • ...通过迁移它来添加新模块
  • ...通过运行其迁移来删除模块
  • ...在每次运行中选择要运行迁移的模块
  • ...声明模块依赖关系(即将推出)
  • ...根据模块使用不同的迁移模板(即将推出)

资源

要求

  • Yii 1.1.6或更高版本(MigrateCommand从该版本引入),如果您复制MigrateCommand和CDbMigration,您应该能够使用此扩展与任何yii版本一起使用。

安装

  • protected/extensions下提取发布文件。
  • 将以下内容添加到yiic命令的配置文件
'commandMap' => array(
	'migrate' => array(
		// alias of the path where you extracted the zip file
		'class' => 'application.extensions.yiiext.commands.migrate.EMigrateCommand',
		// this is the path where you want your core application migrations to be created
		'migrationPath' => 'application.db.migrations',
		// the name of the table created in your database to save versioning information
		'migrationTable' => 'tbl_migration',
		// the application migrations are in a pseudo-module called "core" by default
		'applicationModuleName' => 'core',
		// define all available modules (if you do not set this, modules will be set from yii app config)
		'modulePaths' => array(
			'admin'      => 'application.modules.admin.db.migrations',
			'user'       => 'application.modules.user.db.migrations',
			'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', // ...
		),
		// the name of the application component that should be used to connect to the database
		'connectionID'=>'db',
		// alias of the template file used to create new migrations
		'templateFile'=>'application.db.migration_template',
	),
),

请注意:如果您之前已经使用过MigrateCommand,请确保将模块列添加到您的迁移表中

ALTER TABLE `tbl_migration` ADD COLUMN `module` varchar(32) DEFAULT NULL;
UPDATE `tbl_migration` SET module='core';

使用方法

###通用用法

您可以通过运行yiic migrate help来查看所有参数及其使用示例。

基本用法在Yii definitive guide中解释。如果您之前没有使用过数据库迁移,请首先阅读它们。扩展迁移命令的使用与原生命令非常相似。唯一不同的命令是create,您必须另外指定模块名称

yiic migrate create modulename create_user_table

这将创建一个名为'create_user_table'的新迁移,位于'modulename'模块中。原生用法

yiic migrate create create_user_table

创建一个名为'create_user_table'的新迁移,位于应用程序(core)中。

###--module参数

在其他所有命令(updownhistorynewtomark)中,您可以使用参数--module=<modulenames>,其中<modulenames>可以是逗号分隔的模块名称列表或单个模块名称。此参数将限制当前命令只影响指定的模块。一些示例

yiic migrate new --module=core

这将显示core模块的所有新迁移

yiic migrate up 5 --module=core,user

将迁移core和user模块中的下一个5个新迁移。如果其他模块中存在新迁移,将忽略它们。

yiic migrate history --module=core,user

将展示过去已应用于核心模块和用户模块的迁移。如果您没有指定模块,命令的行为类似于原生命令,并为所有模块执行迁移。

###添加模块

只需在您的配置中启用它,然后运行 yiic migrate up --module=yourModule

###删除模块

运行 yiic migrate to m000000_000000 --module=yourModule。为了使其正常工作,您所有的迁移都必须正确实现 down()-方法。