• Stars
    star
    106
  • Rank 324,899 (Top 7 %)
  • Language
    PHP
  • Created almost 10 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Yii2 Gii-tools for create migration files

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("[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);

More Repositories

1

unused-scanner

Detect unused composer dependencies
PHP
430
star
2

yii2-adminlte-widgets

PHP
63
star
3

InteractiveJobs

Laravel - vue interactive jobs demo
PHP
36
star
4

yii2-codestat

Yii2 code statistic
PHP
34
star
5

php-async-benchmarks

PHP
24
star
6

yii2-opcache

Opcache management for yii2 from console or adminlte-based gui module
PHP
16
star
7

yii2-array-structure-validator

Validate complex array structure
PHP
13
star
8

yii2-iconpicker

widget wrapper for bootstrap-iconpicker
PHP
11
star
9

coloro

A console tool for output text with highlighted hex colors
Python
11
star
10

metaphone

Russian metaphone algorithm implementation
PHP
9
star
11

yii2-fixturegii

Yii2 - generator for fixture classes, faker templates, fixture data files from table.
PHP
9
star
12

yii2-muffin-factory

Generate ActiveRecord fixtures on fly
PHP
9
star
13

composer-recovery

Helper for recovery composer dependency list (if you lost composer.json)
PHP
9
star
14

yii2-adminlte3-asset

AdminLte3 asset for Bootstrap4
PHP
7
star
15

dockerstack

docker-stack collection
Dockerfile
6
star
16

yii2-fractal

A set of utils and actions for build API following JSON:Api specification, based on league/fractal
PHP
5
star
17

pgjsonb_test

Test postgres jsonb performance
PHP
4
star
18

yii2-maintenance

Config focused maintenance component
PHP
4
star
19

yii2-adminlte3-widgets

AdminLte3 widgets for Bootstrap4
PHP
4
star
20

circular-queue

Circular Queue with redis implementation for distribution of shared data
PHP
4
star
21

fakerprovider

Providers for faker
PHP
3
star
22

yii2-redisman-app

RedisManager Application
PHP
3
star
23

yii2-form-prefiller

Remember user-filled form data, prefill forms with remembered data in cookie/session/redis/db
PHP
3
star
24

yii2-skeletest

Generate test skeletons for file or whole directory with target file methods
PHP
3
star
25

yii2-multifs

Multifs manager and uploader based on League\Flysystem\MountManager, inspired of trntv\filekit
PHP
3
star
26

yii2-metacrumbs

alternative way for work with breadcrumbs and meta data
PHP
2
star
27

yii2-giitwig

default yii2-crud templates in twig.format
PHP
2
star
28

salt-testlab

Local salt state testing environment
Dockerfile
2
star
29

cli_translate

Useful console translation tool/ With features: translate text from clipboard and store translation logs
Python
2
star
30

yii2-validatorpack

Validator Collection
PHP
1
star
31

rust_learning

Rust
1
star
32

pacman-recover

Actual pacman-recover
Shell
1
star
33

laravel-file-api

Flexible api for browse and manage folders and files, uploads, tranform images
1
star
34

yii2-arsync

PHP
1
star
35

php-acme-client

ACME Client supported endpoint for ACME v2, written with PHP.
PHP
1
star
36

ucopy

Copy files from one or more directories to target directory with union mode
Python
1
star
37

deployme

PHP
1
star