Stars: 106
Forks: 29
Pull Requests: 13
Issues: 36
Watchers: 9
Last Updated: 2021-10-02 19:16:01
Yii2 Gii-tools for create migration files
License:
Languages: PHP
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)
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
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:
/**
* @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{
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',
],
],
],
];
\Yii::$container->set(IMigrationTableResolver::class, YourTableResolver::class);