Yii 2.0: yii2-migration-utility

Automatically writes the create tables for migrations or create tables in general. Uses MySQL
3 followers

Yii2 Migration Utility

Updated July 21, 2014

This is a simple utility that writes the create table statement for you. The table(s) must already exist.

Supports

  • MySQL
  • MsSQL
  • PgSQL
  • SQLite

It automatically writes out all:

  • tables
  • columns
  • column types
  • column defaults
  • primary keys
  • foreign key
  • does not add indexes

Note: Foreign keys default to CASCADE / DELETE so you may need to manually change these.

Note: $tableOptions is added so make sure you have a var set.

Note: $dbType is used with the if/then statements.

$dbType = Yii::$app->db->driverName;

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist "c006/yii2-migration-utility" "dev-master"

or add

"c006/yii2-migration-utility": "dev-master"

to the require section of your composer.json file.

Required

Update either config/web.php (basic) or config/main.php (advanced)

        'modules'    => [
            ...
            ...
            ...
            'utility' => [
                'class' => 'c006\utility\migration\Module',
            ],
        ],

The tables must already exist in website schema.

Usage

http://___[Your_Domain]___/utility/index

Workbench showing the user table:

alt text

Image of demo page:

alt text

Errors

If you see this error.

Error Message

In this file vendor/c006/yii2-migration-utility/assets/AppAssets.php

comment out these lines.

        public $depends = [
            // 'yii\web\YiiAsset',
            // 'yii\widgets\ActiveFormAsset',
            // 'yii\bootstrap\BootstrapAsset',
        ];

Comments / Suggestions

Please provide any helpful feedback or requests.

Thanks.

Total 2 comments

#17763 report it
jchambers at 2014/07/20 11:18pm
@ThePr0f3550r

I see your point and will update the code.

Thanks for your input.

#17758 report it
ThePr0f3550r at 2014/07/20 07:15pm
You should see example

Good job, but You should see example in core of Yii

For example, for Your table, table user should :

$this->createTable('{{%user}}', [
            'id'            => Schema::TYPE_PK,
            'username'      => Schema::TYPE_STRING . '(25) NOT NULL',
            'email'         => Schema::TYPE_STRING . '(255) NOT NULL',
            'password_hash' => Schema::TYPE_STRING . '(60) NOT NULL',
            'auth_key'      => Schema::TYPE_STRING . '(32) NOT NULL',
 
            // confirmation
            'confirmation_token'   => Schema::TYPE_STRING . '(32)',
            'confirmation_sent_at' => Schema::TYPE_INTEGER,
            'confirmed_at'         => Schema::TYPE_INTEGER,
            'unconfirmed_email'    => Schema::TYPE_STRING . '(255)',
 
            // recovery
            'recovery_token'   => Schema::TYPE_STRING . '(32)',
            'recovery_sent_at' => Schema::TYPE_INTEGER,
 
            // block
            'blocked_at' => Schema::TYPE_INTEGER,
 
            // RBAC
            'role' => Schema::TYPE_STRING . '(255)',
 
            // trackable
            'registered_from' => Schema::TYPE_INTEGER,
            'logged_in_from'  => Schema::TYPE_INTEGER,
            'logged_in_at'    => Schema::TYPE_INTEGER,
 
            // timestamps
            'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
            'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',
        ], $tableOptions);

Not only think MySQL but globally :)

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet