📜 ⬆️ ⬇️

Migration appeared in Yii

Good news for everyone who uses or looks at the PHP framework Yii. The expected opportunity for many is migration.

Migrations are very important for team development, when not only the code is constantly changing, but also the database structure. So that everyone does not use his hands to change other team members and there are migrations.

How does typical migration work occur?
')
Developer Andrei creates migration

yiic migrate create --name=create_news_table

Goes to protected / migrations and fills it with useful code:

 class m20101129185401_create_news_table extends CDbMigration {
     public function up () {
         $ this-> createTable ('tbl_news', array (
             'id' => 'pk',
             'title' => 'string NOT NULL',
             'content' => 'text',
         ))
     }
 
     / *
     public function down () {
     }
     * /
 }


Here you can use absolutely any code, for example, to clear the cache or assets .

Then Andrey somehow transfers the migration to Ivan. Via SVN, mail or FTP - it does not matter (better, of course, through the version control system). Ivan applies migration:

yiic migrate up

and works quietly with the new code.

A more detailed description in Russian will be on yiiframework.ru in the near future (or, at least, before the release).

Migrations will be included in the next release of Yii, but for now you can play around with the trunk. The syntax may change slightly before release.

Source: https://habr.com/ru/post/109120/


All Articles