matasarei / rumble
此包已被废弃,不再维护。未建议替代包。
Symfony 4 的 DynamoDB 迁移包
4.0.1
2019-03-04 14:29 UTC
Requires
- aws/aws-sdk-php: ^3.0
- symfony/console: ^4.0
- symfony/framework-bundle: ^4.0
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2024-06-09 20:30:55 UTC
README
基于原始 Rumble 库的 Symfony 4 DynamoDB 迁移包。
类定义
- 迁移:您创建的每个迁移文件(类)都必须继承 rumble 的
Migration
类,并必须定义一个up
方法。 - 种子:您创建的每个种子文件(类)都必须继承 rumble 的
Seeder
类,并必须定义一个seed
方法。
使用 Rumble
- 迁移:要应用迁移,运行
./bin/console rumble:migrate
- 种子:要执行种子文件,运行
./bin/console rumble:seed
支持的 DynamoDB 功能
目前,rumble
只支持以下 DynamoDB 功能
- 创建表
- 更新表
- 删除表
- 添加项
- 批量写入项
安装
-
将包添加到您的项目中:
composer require matasarei/rumble
-
添加配置文件:
config/packages/rumble.yaml
默认内容
rumble: migrations_dir: 'migrations' # <project_root>/migrations/... (optional) seeds_dir: 'seeds' # <project_root>/seeds/... (optional) version: '2012-08-10' # (default, optional) region: 'dev' key: 'dev' secret: 'dev' endpoint: 'http://dynamodb:8000'
您也可以通过添加额外的配置来覆盖值,例如
- 在
config/packages/dev/rumble.yaml
中为dev
环境添加配置; - 在
config/packages/test/rumble.yaml
中为test
或qa
环境添加配置; - 在
config/packages/prod/rumble.yaml
中为prod
环境添加配置。
- 在
创建新表
<?php // migrations/CreateAppRecordsTable.php use Matasar\Bundle\Rumble\Migration; class CreateAppRecordsTable extends Migration { public function up() { $table = $this->table('test_table'); // table name. $table->addAttribue('test_field', 'S'); // primary key data type - String (S) $table->addHash('test_field'); $table->setWCU(1); // Write Capacity Unit (Provisioned write throughput) $table->setRCU(1); // Read Capacity Unit (Provisioned read throughput) $table->create(); } }
您可以在表设置或 DynamoDB 控制台中更改写入/读取容量,或设置自动扩展。
填充表
<?php // seeds/CreateAppRecordsTable.php use Matasar\Bundle\Rumble\Seeder; class AppRecordsTableSeeder extends Seeder { public function seed() { $table = $this->table('test_table'); $table->addItem(['test_field' => 'First record']); $table->addItem(['test_field' => 'Second record']); $table->save(); } }