purocean / php-db-migration
数据库迁移工具
v0.0.1
2017-01-20 13:17 UTC
Requires
- php: >=5.6.0
This package is not auto-updated.
Last update: 2024-09-28 19:36:32 UTC
README
仅支持 MySQL
使用
// migration.php date_default_timezone_set('PRC'); $migrationConfig = [ 'tablePrefix' => 'test_prefix_', // 表前缀 'migrationsPath' => __DIR__.'/migrations', // 迁移储存位置 'dbConfig' => [ // 数据库配置 'username' => 'root', 'password' => '', 'dsn' => 'mysql:host=localhost;port=3306;dbname=db_migration_test;charset=utf8', ] ]; (new \DbMigration\Cli($migrationConfig))->run();
php migration.php help
迁移示例:/test/migrations/m170119_101310_test_migration.php
功能
- create 创建迁移
- up 升级一个迁移
- down 降级一个迁移
- mark 将某个迁移标记为已升级/未升级
- new 显示未升级迁移
- history 查看迁移历史
测试
cd test vim config.php # 修改数据库配置 php test.php
MySQL
- 执行
- createTable 创建表
- renameTable 重命名表
- dropTable 删除表
- truncateTable 清空表数据
- addColumn 添加列
- dropColumn 删除列
- renameColumn 重命名列
- alterColumn 修改列
- addPrimaryKey 添加主键
- dropPrimaryKey 删除主键
- addForeignKey 添加外键
- dropForeignKey 删除外键
- createIndex 创建索引
- dropIndex 删除索引
- addCommentOnColumn() 添加列注释
- addCommentOnTable 添加表注释
- dropCommentFromColumn 删除列注释
- dropCommentFromTable 删除表注释
- primaryKey 主键
- char 定长字符串
- varchar 可变长字符串
- string 字符串
- text 文本
- smallInteger 小整型
- integer 整型
- bigInteger 大整型
- float 浮点型
- double 双精度浮点型
- decimal 十进制数
- dateTime 日期时间
- timestamp 时间戳
- time 时间
- date 日期
- binary 二进制
- boolean 布尔型
- notNull 非空
- null 可空
- unique 唯一
- defaultValue 默认值
- comment 注释
- unsigned 无符号
- after 在...之后
- first 在第一个
- append 添加到末尾