brtriver / dbup
使用PDO的简单迁移工具
v0.5
2014-10-05 14:50 UTC
Requires
- php: >=5.4.0
- ext-pdo: *
- hamcrest/hamcrest-php: 1.2.0
- phake/phake: v1.0.3
- phpunit/phpunit: 4.2.*
- symfony/console: ~2.5.0
- symfony/event-dispatcher: ~2.5.0
- symfony/finder: ~2.5.0
Suggests
- ext-pdo-mysql: In order to use ikou with MySQL databases.
- ext-pdo-pqsql: In order to use ikou with PostgreSQL databases.
- ext-pdo-sqlite: In oreder to use ikou with SQLite Databases.
This package is not auto-updated.
Last update: 2024-09-23 10:59:28 UTC
README
Dbup 是一个简单的PHP迁移工具。
- 您只需要下载
dbup.phar
。 - Dbup 只有一个
up
命令。Dbup 没有提供down
命令。 - Dbup 只使用简单的SQL,因此您不需要学习ORM或DSL。您只需编写SQL文件,然后调用
up
命令。 - Dbup 只使用PDO类进行迁移。
- Dbup 不需要数据库中的表来进行迁移。
已应用的迁移SQL文件将复制到 .dbup/applied
目录。如果 sql
目录和 .dbup/applied
目录中存在相同的文件,则 up
命令将忽略此SQL文件。
简单...简单..简单..
要求
Dbup 与PHP 5.4.0或更高版本兼容。
安装
安装Dbup非常简单。下载 dbup.phar
并运行 init
,然后创建 .dbup
和 sql
目录,并设置示例 properties.ini
文件和sql文件。
php dbup.phar init
在 .dbup/properties.ini
中更改数据库配置。
[pdo]
dsn = "mysql:dbname=testdatabase;host=localhost"
user = "testuser"
password = "testpassword"
参阅 https://php.ac.cn/manual/en/pdo.construct.php
您还可以将环境变量分配给您的数据库配置文件。Dbup读取以 DBUP_
前缀开头的环境变量,如果名称在 .ini 文件中以 '%%' 包围,则进行读取。例如,以下ini文件中的 user
参数将被替换为环境变量 DBUP_USERNAME
的值,如果已定义。
[pdo]
user = "%%DBUP_USERNAME%%"
命名
您必须按照以下方式命名SQL文件
V[version_number]__[description].sql
V
是前缀。分隔符是 __
(两个下划线)。后缀是 .sql
用法
列出所有命令。
php dbup.phar
您必须将SQL文件写入 sql
目录。
显示状态。
php dbup.phar status
dbup migration status
================================================================================
Applied At | migration sql file
--------------------------------------------------------------------------------
2013-05-01 22:37:32 | V1__sample_select.sql
appending... | V2__sample.sql
appending... | V3__sample.sql
appending... | V20__sample.sql
appending... | V100__sample.sql
在编写新SQL文件后更新数据库。
php dbup.phar up
就是这样。
许可
Dbup采用MIT许可。