GithubHelp home page GithubHelp logo

yii2-migrik's Introduction

Migration Generator

  • 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 03.02.2017 - 2.2.9 version; Fix bug #28; upgrade tests for using YII2 codeception module fix#26 22.12.2016 - 2.2.7 version release add fields for setup default values onUpdate and onDelete in relations 17.12.2016 - 2.2.6 version release merge pr from shirase that fix issue with non-correct gii preview;

20.08.2016 - 2.2 version release

15.08.2016 - 2.1 version release

  • added ability to generate migrations in fluent interface (raw format also available)
  • improved templates; added database initializations
  • improved postresql index retrieving
  • structure improved; separate logic in external classes
  • added ability to set custom class for column generation (@see Customizing section)

13.08.2016 - 2.0 version release with new ability - generate migrations based on table data Possible BC

  • class insolita\migrik\gii\Generator was changed on insolita\migrik\gii\StructureGenerator if you made template customizations - see your gii config and replace old Generator class name

###Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require -dev --prefer-dist insolita/yii2-migration-generator:~2.2

or

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

or add

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

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("[email protected]")
 * @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

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

yii2-migrik's People

Contributors

insolita avatar githubjeka avatar shirase avatar adamzammit avatar

Watchers

James Cloos avatar Marko Kruljac avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.