Skip to content
Generate the schema from an existing database.
PHP
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Add some test case for PostgreSQL Jan 28, 2017
tests Fix test for MySQL timestramp type May 15, 2018
.gitignore Add .idea and remove phpunit.phar in .gitignore May 14, 2018
.travis.yml Add explicit_defaults_for_timestamp for MySQL in .travis.yml May 15, 2018
LICENSE Initial commit Nov 25, 2014
README.md Remove unnecessary some lines in README.md May 15, 2018
composer.json
composer.lock Update dependencies May 15, 2018
phpunit.xml.dist Add the necessary files to the unit test May 8, 2015

README.md

yii2-schemadump

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

Generate the schema from an existing database.

Demo

gif

Installation

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

Usage

Add the following in config/console.php:

return [
    ...
    'components' => [
        ...
    ],
    'controllerMap' => [
        'migrate' => [
            'class' => yii\console\controllers\MigrateController::class,
            'templateFile' => '@jamband/schemadump/template.php',
        ],
        'schemadump' => [
            'class' => jamband\schemadump\SchemaDumpController::class,
            'db' => [
                'class' => yii\db\Connection::class,
                'dsn' => 'mysql:host=localhost;dbname=existing_database_name',
                'username' => 'your_username',
                'password' => 'your_password',
            ],
        ],
    ],
    ...
];

And run schemadump command.

cd /path/to/project
./yii schemadump

Example output:

// user
$this->createTable('{{%user}}', [
    'id' => $this->primaryKey()->comment('主キー'),
    'username' => $this->string(20)->notNull()->unique()->comment('ユーザ名'),
    'email' => $this->string(255)->notNull()->unique()->comemnt('メールアドレス'),
    'password' => $this->string(255)->notNull()->comment('パスワード'),
], $this->tableOptions);

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

Commands

Generates the 'createTable' code. (default)

./yii schemadump
./yii schemadump/create

Generates the 'dropTable' code.

./yii schemadump/drop

Useful commands (for macOS user):

./yii schemadump | pbcopy
./yii schemadump/drop | pbcopy

Check help.

./yii help schemadump

Supports

  • Types
  • Size
  • Unsigned
  • NOT NULL
  • DEFAULT value
  • COMMENT
  • Unique key
  • Foreign key
  • Composite primary keys
  • Primary key without AUTO_INCREMENT
  • ENUM type (for MySQL)
You can’t perform that action at this time.