fabiopaiva / pdo-simple-migration
使用PDO连接进行数据库版本控制
0.1.2
2016-02-13 15:55 UTC
Requires
- php: >=5.4
- ext-pdo: *
- symfony/console: 3.*
- zendframework/zend-code: 2.*
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-14 17:37:35 UTC
README
简单的迁移是一个用于管理数据库版本的最小化工具。
安装
composer require fabiopaiva/pdo-simple-migration
配置
此库尝试在当前工作目录中查找名为config.php的文件,其中包含PDO设置;如果文件不存在,您可以在命令行中发送PDO参数。
config.php(可选)
<?php return [ 'db' => [ 'dsn' => 'mysql:host=localhost;dbname=myDb;port=3306;charset=UTF8', 'username' => 'root', 'password' => 'pass', ], 'table' => 'migrations', 'dir' => 'migrations' ];
table
是用于控制版本化的数据库表名称,默认为 migrations。
dir
是您想要存储迁移文件的路径。
使用方法
状态
列出迁移的当前状态
vendor/bin/migration status
生成
生成一个空的迁移
vendor/bin/migration generate
生成代码示例
<?php namespace PDOSimpleMigration\Migrations; use PDOSimpleMigration\Library\AbstractMigration; class Version20160128130854 extends AbstractMigration { public static $description = "Migration description"; public function up() { //$this->addSql(/*Sql instruction*/); } public function down() { //$this->addSql(/*Sql instruction*/); } }
迁移
迁移到最新版本
vendor/bin/migration migrate
执行
执行特定迁移版本(向上或向下)
vendor/bin/migration execute version --up --down
选项
--dump
如果存在 --dump
参数,迁移将仅在屏幕上转储查询。
--dsn 和 --username
如果您不想创建config.php文件,可以发送 --dsn
设置参数。如果发送 --dsn
参数,您也需要发送 --username
参数。提示将询问您的数据库密码。
--dir
保存迁移类的目录,默认为 migrations
--table
存储迁移版本历史记录的表,默认为 migrations
问题
请向 Github Issue Tracker 报告问题