仅支持 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
- execute
- 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