phpmig.php文件
<?php
use \Phpmig\Adapter;
use Pimple\Container;
$container = new Container();
$container['db'] = function () {
$dbh = new PDO('mysql:dbname=数据库名;host=127.0.0.1','用户名','密码');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
};
# migrations是系统自动创建的迁移记录表
$container['phpmig.adapter'] = function ($c) {
return new Adapter\PDO\Sql($c['db'], 'migrations');
};
# 迁移文件的路径
$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . 'migrations';
// You can also provide an array of migration files
// $container['phpmig.migrations'] = array_merge(
// glob('migrations_1/*.php'),
// glob('migrations_2/*.php')
// );
return $container;
创建迁移
.\vendor\bin\phpmig generate 名称
eg: phpmig generate Product
迁移
.\vendor\bin\phpmig migrate # 会迁移所有为迁移的版本,第一次运行后在数据库创建migrations的表
回滚
.\vendor\bin\phpmig rollback # 根据migrations创建的版本顺序一个一个回滚
批量回滚
.\vendor\bin\phpmig rollback -t 20111101000144 # 这是版本号,也是创建文件顺序,回滚到此文件的迁移状态
其他配置参考github:GitHub – davedevelopment/phpmig: Simple migrations system for php
Was this helpful?
0 / 0