All Projects → Insolita → Yii2 Migrik

Insolita / Yii2 Migrik

Yii2 Gii-tools for create migration files

Projects that are alternatives of or similar to Yii2 Migrik

Php frameworks analysis
php框架源码分析
Stars: ✭ 57 (-42.42%)
Mutual labels:  yii2, yii2-extension
Yii2 Jwt
JWT implementation for Yii2 Authorization process
Stars: ✭ 61 (-38.38%)
Mutual labels:  yii2, yii2-extension
Yii2 Psr Log Target
Yii 2.0 log target that is able to write messages to PSR-3 compatible logger
Stars: ✭ 58 (-41.41%)
Mutual labels:  yii2, yii2-extension
Yii2 Rabbitmq
RabbitMQ Extension for Yii2
Stars: ✭ 52 (-47.47%)
Mutual labels:  yii2, yii2-extension
Ar Linkmany
ActiveRecord behavior for saving many-to-many relations
Stars: ✭ 83 (-16.16%)
Mutual labels:  yii2, yii2-extension
Yii2 Quill
Yii 2 implementation of Quill, modern WYSIWYG editor
Stars: ✭ 52 (-47.47%)
Mutual labels:  hacktoberfest, yii2
Yii2 Collection
Collection extension for Yii 2
Stars: ✭ 62 (-37.37%)
Mutual labels:  yii2, yii2-extension
Yii2 Relation Trait
Yii 2 Models add functionality for load with relation, & transactional save with relation PLUS soft delete/restore feature
Stars: ✭ 47 (-52.53%)
Mutual labels:  yii2, yii2-extension
Csv Grid
Yii2 extension for CSV export
Stars: ✭ 83 (-16.16%)
Mutual labels:  yii2, yii2-extension
Yii2 Schemadump
Generate the schema from an existing database.
Stars: ✭ 78 (-21.21%)
Mutual labels:  yii2, yii2-extension
Yii2 Social Share
With this extension you can share data from your web pages to any social network!
Stars: ✭ 48 (-51.52%)
Mutual labels:  yii2, yii2-extension
Yii2 Gallery Manager
Stars: ✭ 90 (-9.09%)
Mutual labels:  yii2, yii2-extension
Yii2 Editable
Editable widget and column for gridview.
Stars: ✭ 47 (-52.53%)
Mutual labels:  yii2, yii2-extension
Config
Yii2 application runtime configuration support
Stars: ✭ 54 (-45.45%)
Mutual labels:  yii2, yii2-extension
Yii2 Lifecycle Behavior
Define the lifecycle of a model by defining allowed status changes.
Stars: ✭ 47 (-52.53%)
Mutual labels:  yii2, yii2-extension
Sitemap
Site map creation support
Stars: ✭ 59 (-40.4%)
Mutual labels:  yii2, yii2-extension
Yii2 Gravatar
Gravatar Widget for Yii Framework 2
Stars: ✭ 36 (-63.64%)
Mutual labels:  yii2, yii2-extension
Yii2 Cms
Simple CMS extension
Stars: ✭ 42 (-57.58%)
Mutual labels:  yii2, yii2-extension
Yii2 Smarty
Yii 2 Smarty Extension.
Stars: ✭ 67 (-32.32%)
Mutual labels:  hacktoberfest, yii2
Yii2 Aws S3
An Amazon S3 component for Yii2
Stars: ✭ 86 (-13.13%)
Mutual labels:  yii2, yii2-extension

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')
*/
   /**
    * @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);

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].