20.11.2014 Views

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

where the optional parameter limit specifies the number of migrations to be displayed. If<br />

limit is not specified, all available migrations will be displayed.<br />

The first command shows the migrations that have been applied, while the second<br />

command shows the migrations that have not been applied.<br />

Modifying Migration History<br />

Sometimes, we may want to modify the migration history to a specific migration version<br />

without actually applying or reverting the relevant migrations. This often happens when<br />

developing a new migration. We can use the the following command to achieve this goal.<br />

yiic migrate mark 101129_185401<br />

This command is very similar to yiic migrate to command, except that it only modifies the<br />

migration history table to the specified version without applying or reverting the migrations.<br />

Customizing Migration Command<br />

There are several ways to customize the migration command.<br />

Use Command Line Options<br />

The migration command comes with four options that can be specified in command line:<br />

• interactive: boolean, specifies whether to perform migrations in an interactive mode.<br />

Defaults to true, meaning the user will be prompted when performing a specific<br />

migration. You may set this to false should the migrations be <strong>do</strong>ne in a background<br />

process.<br />

• migrationPath: string, specifies the directory storing all migration class files. This must<br />

be specified in terms of a path alias, and the corresponding directory must exist. If not<br />

specified, it will use the migrations sub-directory under the application base path.<br />

• migrationTable: string, specifies the name of the database table for storing migration<br />

history information. It defaults to tbl_migration. The table structure is version varchar<br />

(255) primary key, apply_time integer.<br />

• connectionID: string, specifies the ID of the database application component.<br />

Defaults to 'db'.<br />

• templateFile: string, specifies the path of the file to be served as the code template<br />

for generating the migration classes. This must be specified in terms of a path alias<br />

(e.g.application.migrations.template). If not set, an internal template will be used.<br />

Inside the template, the token {ClassName} will be replaced with the actual migration<br />

class name.<br />

To specify these options, execute the migrate command using the following format<br />

yiic migrate up --option1=value1 --option2=value2 ...<br />

For example, if we want to migrate for a forum module whose migration files are located<br />

within the module'smigrations directory, we can use the following command:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!