PHP Classes

YII2 Migrik: Create migration files for applications using YII2

Recommend this page to a friend!
  Info   View files Documentation   View files View files (51)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2022-09-15 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 18 This week: 1All time: 10,764 This week: 491Up
Version License PHP version Categories
yii2-migrik 1.0MIT/X Consortium ...5PHP 5, Databases, Utilities and Tools
Description Author

This package can create migration files for applications using YII2.

It provides classes that can be used by the GII file generator of the YII2 framework project to generate database table migration files for projects that use this framework.

The classes can use annotations that may be contained in model classes to extract the information that maps model class objects into database tables.

It can generate migration files for all application database tables, one table, or a list of tables.

Currently

Innovation Award
PHP Programming Innovation award nominee
September 2022
Number 9
Most applications that use the MVC (Model View Controller) design pattern to implement model classes to map application data objects into database table records.

When those applications need to change the model class structure, they also have to update the database schema of the tables to modify the table to store the model class object variables.

MVC-based frameworks like YII2 can support the concept of migrations to perform this kind of application changes to the model classes.

This package implements a migration solution for YII2 framework-based applications that simplifies the generation of migration files for these applications.

Manuel Lemos
Picture of Insolita
  Performance   Level  
Name: Insolita <contact>
Classes: 14 packages by
Country: Russian Federation Russian Federation
Age: 37
All time rank: 354397 in Russian Federation Russian Federation
Week rank: 9 Up1 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 9x

Details

Migration Generator

Latest Stable Version Total Downloads License

- 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

The preferred way to install this extension is through composer.

Either run

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

or add

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

to the require-dev section of your composer.json file.

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

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

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

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

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

__Supported column annotations:__ - As separate annotation above class or above current variable

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

- As addition to @property or @var definition

    /
     * @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

vendor/insolita/yii2-migration-generator/gii/default_structure //schema migrations

vendor/insolita/yii2-migration-generator/gii/default_data //data migrations

to some project directory, for example

@backend/gii/templates/migrator_data;

@backend/gii/templates/migrator_schema;

Change gii configuration like this

$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

    
  Files folder image Files  
File Role Description
Files folder imagecontracts (4 files)
Files folder imagegii (7 files, 3 directories)
Files folder imageresolver (8 files)
Files folder imagetests (5 files, 4 directories)
Plain text file Bootstrap.php Class Class source
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file codeception.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  contracts  
File Role Description
  Plain text file IMigrationColumnResolver.php Class Class source
  Plain text file IMigrationTableResolver.php Class Class source
  Plain text file IModelResolver.php Class Class source
  Plain text file IPhpdocResolver.php Class Class source

  Files folder image Files  /  gii  
File Role Description
Files folder imagedefault_bymodel (1 file)
Files folder imagedefault_data (2 files)
Files folder imagedefault_structure (3 files)
  Plain text file ByModelGenerator.php Class Class source
  Plain text file DataGenerator.php Class Class source
  Accessible without login Plain text file form_bymodel.php Example Example script
  Accessible without login Plain text file form_data.php Example Example script
  Accessible without login Plain text file form_structure.php Example Example script
  Plain text file GeneratorTrait.php Class Class source
  Plain text file StructureGenerator.php Class Class source

  Files folder image Files  /  gii  /  default_bymodel  
File Role Description
  Accessible without login Plain text file migration.php Aux. Auxiliary script

  Files folder image Files  /  gii  /  default_data  
File Role Description
  Accessible without login Plain text file data_batch.php Example Example script
  Accessible without login Plain text file data_model.php Example Example script

  Files folder image Files  /  gii  /  default_structure  
File Role Description
  Accessible without login Plain text file mass.php Example Example script
  Accessible without login Plain text file migration.php Example Example script
  Accessible without login Plain text file relation.php Example Example script

  Files folder image Files  /  resolver  
File Role Description
  Plain text file BaseColumnResolver.php Class Class source
  Plain text file FluentColumnResolver.php Class Class source
  Plain text file ModelResolver.php Class Class source
  Plain text file PgFluentColumnResolver.php Class Class source
  Plain text file PgRawColumnResolver.php Class Class source
  Plain text file PhpDocResolver.php Class Class source
  Plain text file RawColumnResolver.php Class Class source
  Plain text file TableResolver.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagedata (2 files)
Files folder imagehelpers (1 file, 1 directory)
Files folder imagemigrations (1 file)
Files folder imageunit (11 files)
  Accessible without login Plain text file .env.dist Data Auxiliary data
  Accessible without login Plain text file bootstrap.php Example Example script
  Plain text file config.php Class Class source
  Plain text file PrivateTestTrait.php Class Class source
  Accessible without login Plain text file unit.suite.yml Data Auxiliary data

  Files folder image Files  /  tests  /  data  
File Role Description
  Plain text file HistoryItem.php Class Class source
  Plain text file TestModel.php Class Class source

  Files folder image Files  /  tests  /  helpers  
File Role Description
Files folder image_generated (1 file)
  Plain text file UnitTester.php Class Class source

  Files folder image Files  /  tests  /  helpers  /  _generated  
File Role Description
  Plain text file UnitTesterActions.php Class Class source

  Files folder image Files  /  tests  /  migrations  
File Role Description
  Plain text file m170428_223742_test_migration.php Class Class source

  Files folder image Files  /  tests  /  unit  
File Role Description
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file ByModelGeneratorTest.php Class Class source
  Plain text file FluentColumnResolverTest.php Class Class source
  Plain text file GeneratorTraitTest.php Class Class source
  Plain text file ModelResolverTest.php Class Class source
  Plain text file PgFluentColumnResolverTest.php Class Class source
  Plain text file PgRawColumnResolverTest.php Class Class source
  Plain text file PhpdocResolverTest.php Class Class source
  Plain text file RawColumnResolverTest.php Class Class source
  Plain text file TableResolverMysqlTest.php Class Class source
  Plain text file TableResolverPgTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:18
This week:1
All time:10,764
This week:491Up