spacetab-io / rdb
从代码控制的最简单的异步PHP迁移。
1.0.3
2020-05-08 11:04 UTC
Requires
- php: ^7.4
- amphp/amp: ^2.4
- league/flysystem: ^1.0
- psr/log: ^1.1
- symfony/console: ^5.0
Requires (Dev)
- amphp/mysql: ^2.0
- amphp/phpunit-util: ^1.3
- amphp/postgres: ^1.2
- phpstan/phpstan: ^0.12.18
- phpunit/phpunit: ^9.0
- symfony/var-dumper: ^5.0
This package is auto-updated.
Last update: 2024-09-19 17:21:11 UTC
README
从代码控制的最简单的PHP迁移。
特性
- 使用 Amp 构建异步迁移。
- 开发用于从 代码 和 命令行界面 使用。
- 开发用于使用任何数据库的工具。目前支持官方的 Amp Postgres & MySQL 客户端。
- 您可以扩展控制台命令以使用自定义配置定义的工具,而不是始终使用
--connect
标志。 - 您可以从任何地方使用迁移/种子文件,并且可以使用任何路径。
安装
安装工具
composer require spacetab-io/rdb
并安装数据库客户端,例如
composer require amphp/postgres
使用方法
use Spacetab\Rdb\Notifier\StdoutNotifier; use Spacetab\Rdb\Rdb; use Spacetab\Rdb\Driver; use Amp\Postgres; use Amp\Postgres\ConnectionConfig; Amp\Loop::run(function () { $config = ConnectionConfig::fromString('host=localhost user=root dbname=test'); /** @var Postgres\Pool $pool */ $pool = Postgres\pool($config); $driver = new Driver\SQL\Postgres($pool); $rdb = new Rdb($driver, new StdoutNotifier()); // Optional. By default notifications is muted. $migrator = $rdb->getMigrator(); yield $migrator->install(); yield $migrator->migrate(); yield $rdb->getSeeder()->run(); });
从命令行界面使用
vendor/bin/rdb list
Rdb – dead-simple async PHP migrations controlled from code. (v1.0).
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Displays help for a command
list Lists commands
make
make:migration Create a new migration files
make:seed Create a new seeder file
migrate
migrate:down [migrate:rollback] Rollback the last database migration
migrate:install Create the migration repository
migrate:refresh Reset and re-run all migrations
migrate:reset Rollback all database migrations
migrate:status Show the status of each migration
migrate:up Run the database migrations
seed
seed:run Seed the database with records
依赖
- >= PHP 7.4
- Composer 用于安装包
测试
- 单元测试
vendor/bin/phpunit --testsuite Unit
- 集成测试
vendor/bin/phpunit --testsuite Integration
。接受环境变量:PHPUNIT_RDB_PG_HOST
,PHPUNIT_RDB_PG_PORT
,PHPUNIT_RDB_PG_DBNAME
,PHPUNIT_RDB_PG_USER
,PHPUNIT_RDB_PG_PWD
许可证
MIT 许可证
版权 © 2020 spacetab.io, Inc. https://spacetab.io
特此授予任何人免费获得此软件及其相关文档文件(“软件”)的副本(以下简称“软件”)的权利,以不受限制地处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件的副本,并允许向软件提供的人以本条款为条件这样做
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和无侵权性保证。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任承担责任,无论是在合同、侵权或其他行为中产生的,源于、因或与该软件或其使用或其他交易有关。