hzhihua / yii2-dump
从现有数据库生成模式
1.0.3
2018-05-02 06:41 UTC
Requires
- php: >=5.5.0
This package is not auto-updated.
Last update: 2024-09-15 09:36:51 UTC
README
从现有数据库生成迁移文件
github: https://github.com/Hzhihua/yii2-dump
码云: http://git.oschina.net/hzhihua/yii2-dump
演示
测试环境
- PHP >= 5.5.0
- MySQL(5.6.36)
安装
composer require --prefer-dist "hzhihua/yii2-dump:1.0.3"
配置
在控制台/config/main.php中添加以下内容
简单配置
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”, ], ], ];
详细配置 查看
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”, // ... ... ], ], ];
默认表选项
ENGINE=InnoDB CHARACTER SET=utf8 COLLATE=utf8_unicode_ci
在 "@vendor/hzhihua/yii2-dump/src/Migration.php" 文件中定义 查看
默认限制
0,1000
默认筛选表
migration
提示
在运行 "./yii migrate" 命令之前,您可能需要删除名为 "*_init.php" 的迁移文件,因为当您运行 "./yii dump" 命令时,它将生成 "{{%user}}" 表文件,并且具有 "*_init.php" 的文件名也会创建 "{{%user}}" 表。它会提示您 "{{%user}}" 已经存在。
简单用法
运行
dump
命令。
cd /path/to/your-project
./yii dump # default action: generate, it will gerate migration file
命令
检查帮助
./yii help dump
打印所有不带表前缀的表名
./yii dump/list
生成所有表的迁移文件(默认筛选迁移表)
./yii dump
or
./yii dump/generate
生成所有表的迁移文件,但只有0到10之间的数据
./yii dump -limit=10
仅生成table1,table2迁移文件
./yii dump -table=table1,table2
仅生成table1,table2迁移文件,并且只有table1将导出表数据
./yii dump -table=table1,table2 -data=table1
生成所有迁移表文件,但不包括table1,table2
./yii dump -filter=table1,table2
打印所有迁移表文件的代码(默认筛选迁移表)
./yii dump/create
在终端显示 'createTable' 代码。
./yii dump/create
在终端显示 'dropTable' 代码。
./yii dump/drop
-type 参数
./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
有用的命令(针对macOS用户)
./yii dump | pbcopy
./yii dump/drop | pbcopy
支持
- 类型
- 大小
- 无符号
- NOT NULL
- 默认值
- 注释
- 唯一键
- 外键
- 主键
- ENUM类型(针对MySQL)
- AUTO_INCREMENT
不支持
AUTO_INCREMENT