Skip to content

This command to generate the schema from an existing database.

License

Notifications You must be signed in to change notification settings

cybercog/yii2-schemadump

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yii2-schemadump

Latest Stable Version Total Downloads Latest Unstable Version License

This command to generate the schema from an existing database.

Demo

gif

Installation

php composer.phar require --dev --prefer-dist jamband/yii2-schemadump "*"

or add in composer.json (require-dev section)

"jamband/yii2-schemadump": "*"

Usage

Add the following in config/console.php:

<?php
return [
    ...
    'components' => [
        ...
    ],
    'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'templateFile' => '@jamband/schemadump/template.php',
        ],
        'schemadump' => [
            'class' => 'jamband\schemadump\SchemaDumpController',
        ],
    ],
    ...
];

And run schemadump command.

cd /path/to/project
./yii schemadump <existing_database_name>

Example output:

// user
$this->createTable('{{%user}}', [
    'id' => Schema::TYPE_PK . " COMMENT '主キー'",
    'username' => Schema::TYPE_STRING . "(255) NOT NULL COMMENT 'ユーザ名'",
    'email' => Schema::TYPE_STRING . "(255) NOT NULL COMMENT 'メールアドレス'",
    'password' => Schema::TYPE_STRING . "(255) NOT NULL COMMENT 'パスワード'",
], $this->tableOptions);

Copy the output code and paste it into a migration file.

Commands

Generates the 'createTable' code. (default)

./yii schemadump <existing_database_name>
./yii schemadump/create <existing_database_name>

Generates the 'dropTable' code.

./yii schemadump/drop <existing_database_name>

Useful commands (for OS X user):

./yii schemadump <existing_database_name> | pbcopy
./yii schemadump/drop <existing_database_name> | pbcopy

Check help.

./yii help schemadump

Supports

  • Types
  • Size
  • Unsigned
  • NOT NULL
  • DEFAULT value
  • COMMENT
  • Foreign key
  • Composite primary keys
  • Primary key without AUTO_INCREMENT
  • ENUM type (for MySQL)

About

This command to generate the schema from an existing database.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages

  • PHP 100.0%