hzhihua/yii2-dump
Composer 安装命令:
composer require hzhihua/yii2-dump
包简介
Generate the schema from an existing database
README 文档
README
Generate migration file from an existing database
github: https://github.com/Hzhihua/yii2-dump
oschina: http://git.oschina.net/hzhihua/yii2-dump
Demo
Test Environment
- PHP >= 5.5.0
- MySQL(5.6.36)
Installation
composer require --prefer-dist "hzhihua/yii2-dump:1.0.3"
Configuration
Add the following in console/config/main.php:
Simple Configuration
return [ 'controllerMap' => [ 'dump' => [ 'class' => 'hzhihua\dump\DumpController', 'filePrefix' => '123456_654321', 'tableOptions' => 'ENGINE=InnoDB CHARACTER SET=utf8 COLLATE=utf8_unicode_ci', // if mysql >= 5.7, you can set “ENGINE=InnoDB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci”, ], ], ];
Detail Configuration see
return [ 'controllerMap' => [ 'dump' => [ 'class' => 'hzhihua\\dump\\DumpController', 'db' => 'db', // Connection 'templateFile' => '@vendor/hzhihua/yii2-dump/templates/migration.php', 'generatePath' => '@console/migrations', 'table' => 'table1,table2', // select which table will be dump(default filter migration table) 'filter' => 'table3,table4', // table3 and table4 will be filtered when generating migration file 'limit' => '0,1000', // select * from tableName limit 0,1000 'filePrefix' => '123456_654321', 'tableOptions' => 'ENGINE=InnoDB CHARACTER SET=utf8 COLLATE=utf8_unicode_ci', // if mysql >= 5.7, you can set “ENGINE=InnoDB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci”, // ... ... ], ], ];
Default Table Options
ENGINE=InnoDB CHARACTER SET=utf8 COLLATE=utf8_unicode_ci
it was defined at "@vendor/hzhihua/yii2-dump/src/Migration.php" file see
Default Limit
0,1000
Default Filter Table
migration
Tips
You may neet to remove the migration file that its name is "*_init.php" before you run "./yii migrate" commond. because it will generate "{{%user}}" table file when you run "./yii dump" commond and the file name with "*_init.php" also create "{{%user}}" table. it will tip you "{{%user}}" has always exits.
Simple Usage
run
dumpcommand.
cd /path/to/your-project
./yii dump # default action: generate, it will gerate migration file
Commands
Check help
./yii help dump
print all over the table name without table prefix
./yii dump/list
generate all over the table migration file(default filter migration table)
./yii dump
or
./yii dump/generate
generate all over the table migration file but it only had some data between 0 and 10
./yii dump -limit=10
only generate table1,table2 migration file
./yii dump -table=table1,table2
only generate table1,table2 migration file and only table1 will be dumped table data
./yii dump -table=table1,table2 -data=table1
generate all over the migration table file without table1,table2
./yii dump -filter=table1,table2
print all over the code of migration table file(default filter migration table)
./yii dump/create
Display the 'createTable' code at the terminal.
./yii dump/create
Display the 'dropTable' code at the terminal.
./yii dump/drop
-type params
./yii dump -type=0/1/2/3
>>> -type=0 generate table migration file,
>>> -type=1 generate table data migration file,
>>> -type=2 generate add key migration file,
>>> -type=3 generate add foreign key migration file
Useful commands (for macOS user):
./yii dump | pbcopy
./yii dump/drop | pbcopy
Supports
- Types
- Size
- Unsigned
- NOT NULL
- DEFAULT Value
- COMMENT
- Unique key
- Foreign key
- Primary key
- ENUM type (for MySQL)
- AUTO_INCREMENT
Not Supports
AUTO_INCREMENT
hzhihua/yii2-dump 适用场景与选型建议
hzhihua/yii2-dump 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29.48k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2017 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「generator」 「command」 「extension」 「migration」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hzhihua/yii2-dump 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hzhihua/yii2-dump 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hzhihua/yii2-dump 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Dibi is Database Abstraction Library for PHP
A Wrapper for exec and it's results
Symfony bundle to monitor and execute commands
Store your language lines in the database, yaml or other sources
Shell command module for PHP.
统计信息
- 总下载量: 29.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 5
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-09-10
