2017 © Pedro Peláez
 

yii2-extension yii2-migration-generator

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

image

insolita/yii2-migration-generator

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  • Thursday, June 14, 2018
  • by Insolita
  • Repository
  • 10 Watchers
  • 71 Stars
  • 18,595 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 22 Forks
  • 2 Open issues
  • 18 Versions
  • 12 % Grown

The README.md

Migration Generator

Latest Stable Version Total Downloads License, (*1)

  • generate migration files (not dumps!) with indexes, and foreign keys, for one table, comma separated list of tables, by part of table name, for all tables by
  • generate migrations based on table data - in two ways - as batchInsert Query or as insert via model
  • generate migrations based on PHPDOC and model properties

CHANGELOG

Installation

NOTE : Use 2.x versions for yii <=2.0.13, (*2)

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

composer require --dev --prefer-dist insolita/yii2-migration-generator:~3.1

or add, (*5)

"insolita/yii2-migration-generator": "~3.1"

to the require-dev section of your composer.json file., (*6)

Just install, go to gii and use (By default composer bootstrap hook), (*7)

ANNOTATION SYNTAX

In general the syntax of column definitions is based on style of yii-migration, only separated by "|" and provide a little more opportunities for reducing code - as you see in examples - empty brackets not necessary - also shortcut expr() will be replaced to defaultExpression() and default() to defaultValue, (*8)

You can add annotations in your model(not necessary AR or yii\base\Model or Object or stdClass), (*9)

@db (db2) - specify connection id required for migration 'db' - by default", (*10)

@table ({{%my_table}})- specify table for migration", (*11)

Supported column annotations: - As separate annotation above class or above current variable, (*12)

php /** * @column (name) string|notNull|default('SomeValue') */, (*13)

  • As addition to @property or @var definition, (*14)

    /**
     * @var int $id @column pk()
     */
    public $id;
    /**
     * @var string $route @column string(100)|notNull()
     */
    public $route;
    
    
/**
 * @property integer    $id         @column pk|comment("Id")
 * @property string     $username   @column string(100)|unique|notNull|default("Vasya")
 * @property string     $email      @column string(200)|unique()|defaultValue("123@mail.ru")
 * @property string     $password   @column string(200)|notNull|expr(null)
 * @property string     $created_at @column string(200)|notNull|expr('CURRENT_TIMESTAMP')
 */
class TestModel extends ActiveRecord{

Customizing

Use Own templates

Copy default templates from folders, (*15)

vendor/insolita/yii2-migration-generator/gii/default_structure //schema migrations, (*16)

vendor/insolita/yii2-migration-generator/gii/default_data //data migrations, (*17)

to some project directory, for example, (*18)

@backend/gii/templates/migrator_data;, (*19)

@backend/gii/templates/migrator_schema;, (*20)

Change gii configuration like this, (*21)

$config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['127.0.0.1', 'localhost', '::1'],
    'generators' => [
        'migrik' => [
            'class' => \insolita\migrik\gii\StructureGenerator::class,
            'templates' => [
                'custom' => '@backend/gii/templates/migrator_schema',
            ],
        ],
        'migrikdata' => [
            'class' => \insolita\migrik\gii\DataGenerator::class,
            'templates' => [
                'custom' => '@backend/gii/templates/migrator_data',
            ],
        ],
    ],
];
Use own resolver for definition of columns
  • create new class, inherited from \insolita\migrik\resolver*ColumnResolver
    • override required methods, or create methods for exclusive columns based on database types - see insolita\migrik\resolver\BaseColumnResolver resolveColumn() phpdoc and realization
Use own resolver for definition of indexes or relations
  • create new class, inherited from \insolita\migrik\resolver\TableResolver
  • in bootsrap your apps add injection, (*22)

    \Yii::$container->set(IMigrationTableResolver::class, YourTableResolver::class);, (*23)

The Versions

14/06 2018

dev-master

9999999-dev

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

29/04 2017

2.3

2.3.0.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

24/03 2017

2.2.10

2.2.10.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

03/02 2017

2.2.9

2.2.9.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

03/02 2017

dev-dev2.3

dev-dev2.3

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

20/01 2017

2.2.8

2.2.8.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

22/12 2016

2.2.7

2.2.7.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

22/12 2016

dev-dev2.4

dev-dev2.4

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

17/12 2016

2.2.6

2.2.6.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

04/10 2016

2.2.5

2.2.5.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

29/09 2016

2.2.4

2.2.4.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

29/09 2016

2.2.3

2.2.3.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

25/08 2016

2.2.2

2.2.2.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

23/08 2016

2.2.1

2.2.1.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

20/08 2016

2.2

2.2.0.0

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

14/08 2016

2.1

2.1.0.0

gii tool for mass migration generation by Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

13/08 2016

2.0

2.0.0.0

gii tool for mass migration generation by Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2

17/05 2016

1.0.0

1.0.0.0

gii tool for mass migration generation by Schema

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Insolita

extension yii2