2017 © Pedro Peláez
 

yii2-extension migration

Migration generator for Yii 2.

image

flameartlab/migration

Migration generator for Yii 2.

  • Thursday, February 1, 2018
  • by FlameArtLab
  • Repository
  • 0 Watchers
  • 0 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 21 Forks
  • 0 Open issues
  • 21 Versions
  • 0 % Grown

The README.md

Yii2 advanced migration

Latest Stable Version Total Downloads License, (*1)

Migration creator and updater

Generates migration file based on the existing database table and previous migrations., (*2)

NEW in that fork:, (*3)

  • New command fill table_name. You can create migration for copy all table rows. The feature works with empty and NULL values correctly
  • Added migrations for Key indexes (and unique indexes is working fine too)
  • Added comments for tables in create <table> module
  • Bug fixes

Installation

Add the package to your composer.json:, (*4)

{
    "require": {
        "flameartlab/migration": "*"
    }
}

and run composer update or alternatively run composer require flameartlab/migration, (*5)

Basic configuration

Add the following in your configuration file (preferably console configuration file):, (*6)

'components' => [
    // ...
],
'controllerMap' => [
    'migration' => [
        'class' => 'bizley\migration\controllers\MigrationController',
    ],
],

Usage

The following console command are available:, (*7)

php yii migration

or, (*8)

php yii migration/list

Lists all the tables in the database., (*9)

php yii migration/create table_name

Generates migration to create DB table table_name., (*10)

php yii migration/create-all

Generates migrations to create all DB tables., (*11)

php yii migration/update table_name

Generates migration to update DB table table_name., (*12)

php yii migration/update-all

Generates migrations to update all DB tables., (*13)

php yii migration/fill table_name

Generates migration to fill DB table table_name., (*14)

You can generate multiple migrations for many tables at once by separating the names with a comma:, (*15)

php yii migration/create table_name1,table_name2,table_name3

Updating migration

Starting with yii2-migration v2.0 it is possible to generate updating migration for database table., (*16)

  1. History of applied migrations is scanned to gather all modifications made to the table.
  2. Virtual table schema is prepared and compared with current table schema.
  3. Differences are generated as update migration.
  4. In case of migration history not keeping information about the table creating migration is generated.

Command line parameters

command alias description
db Application component's ID of the DB connection to use when generating migrations. default: 'db'
migrationPath p Directory storing the migration classes. default: '@app/migrations'
migrationNamespace n Namespace in case of generating namespaced migration. default: null
templateFile F Template file for generating create migrations. default: '@vendor/bizley/migration/src/views/create_migration.php'
templateFileUpdate U Template file for generating update migrations. default: '@vendor/bizley/migration/src/views/update_migration.php'
useTablePrefix P Whether the table names generated should consider the tablePrefix setting of the DB connection. default: 1
migrationTable t Name of the table for keeping applied migration information. default: '{{%migration}}'
showOnly s Whether to only display changes instead of generating update migration. default: 0
generalSchema g Whether to use general column schema instead of database specific (1). default: 0
fixHistory h Whether to add migration history entry when migration is generated. default: 0
skipMigrations List of migrations from the history table that should be skipped during the update process (2). default: []

(1) Remember that with different database types general column schemas may be generated with different length., (*17)

MySQL examples:

Column varchar(45)
generalSchema=0: $this->string(45)
generalSchema=1: $this->string()
Column int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
generalSchema=0: $this->integer(11)->notNull()->append('AUTO_INCREMENT PRIMARY KEY')
generalSchema=1: $this->primaryKey(), (*18)

(2) Here you can place migrations containing actions that can not be covered by extractor i.e. when there is a migration setting the RBAC hierarchy with authManager component. Such actions should be kept in separated migration and placed on this list to prevent them from being run during the extraction process., (*19)

Renaming

When you rename table or column remember to generate appropriate migration manually otherwise this extension will not generate updating migration (in case of the table) or will generate migration with command to drop original column and add renamed one (in case of the column). This is happening because yii2-migration can only compare two states of the table without the knowledge of how one state turned into another. And while the very result of migration renaming the column and the one dropping it and adding another is the same in terms of structure, the latter makes you lose data., (*20)

Once you add renaming migration to the history it's being tracked by the extension., (*21)

Notes

This extension is tested on MySQL database but should work with all database types supported in Yii 2 core:, (*22)

  • CUBRID (9.3.x and higher)
  • MS SQL Server (2008 and above)
  • MySQL (4.1.x and 5.x)
  • Oracle
  • PostgreSQL (9.x and above)
  • SQLite (2/3)

Let me know if something is wrong with databases other than MySQL (and in case of MySQL let me know as well)., (*23)

As far as I know Yii 2 does not keep information about table indexes (except unique ones) and foreign keys' ON UPDATE and ON DELETE actions so unfortunately this can not be tracked and applied to generated migrations - you have to add it on your own., (*24)

Only history of migrations extending yii\db\Migration class can be properly scanned and only changes applied with default yii\db\Migration methods can be recognised (with the exception of execute(), addCommentOnTable() and dropCommentFromTable() methods). Changes made to table's data (like insert(), delete(), truncate(), etc.) are not tracked., (*25)

The Versions

01/02 2018

dev-master

9999999-dev

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski
by Pavelev Nikolay

yii2 console generator migration migrate

01/02 2018

v2.2.9

2.2.9.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski
by Pavelev Nikolay

yii2 console generator migration migrate

30/01 2018

v2.2.8

2.2.8.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski
by Pavelev Nikolay

yii2 console generator migration migrate

30/01 2018

v2.2.5

2.2.5.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski
by Pavelev Nikolay

yii2 console generator migration migrate

30/01 2018

v2.2.6

2.2.6.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski
by Pavelev Nikolay

yii2 console generator migration migrate

30/01 2018

v2.2.7

2.2.7.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski
by Pavelev Nikolay

yii2 console generator migration migrate

30/01 2018

v2.2.4

2.2.4.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski
by Pavelev Nikolay

yii2 console generator migration migrate

24/11 2017

2.2.1

2.2.1.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration migrate

14/05 2017

2.2.0

2.2.0.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration migrate

12/04 2017

2.1.2

2.1.2.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration migrate

04/04 2017

2.1.1

2.1.1.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration migrate

30/03 2017

2.1

2.1.0.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration migrate

26/03 2017

2.0

2.0.0.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration migrate

10/02 2017

1.1

1.1.0.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration yii 2 migrate

12/09 2016

1.0.6

1.0.6.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration yii 2 migrate

18/07 2016

1.0.5

1.0.5.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration yii 2 migrate

18/07 2016

1.0.4

1.0.4.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration yii 2 migrate

13/07 2016

1.0.3

1.0.3.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration yii 2 migrate

12/07 2016

1.0.2

1.0.2.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration yii 2 migrate

12/07 2016

1.0.1

1.0.1.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration yii 2 migrate

11/07 2016

1.0.0

1.0.0.0

Migration generator for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

yii2 console generator migration yii 2 migrate