lulco / populator
PHP 数据库假数据填充器
1.2.0
2023-08-29 08:31 UTC
Requires
- php: >=7.4 <8.3
- ext-json: *
- ext-pdo: *
- fakerphp/faker: ^1.17
- nette/database: ^3.0
- symfony/console: ^4.2 | ^5.0 | ^6.0
Requires (Dev)
- lulco/phoenix: ^2.3
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-08-29 10:39:19 UTC
README
允许向您的数据库填充假数据
这个库的最好功能是 AutomaticPopulatorCommand,它根据完整的数据库结构填充数据。它分析数据库表树并为每个表创建项目 - 首先创建叶子节点。
// file bin/command.php $database = new Populator\Database\Database('db_name', 'mysql:dbname=db_name;host=db_host', 'db_user', 'db_password'); $populator = new Populator\Command\AutomaticPopulatorCommand($database, ['phoenix_log', 'phinxlog', 'migration_log', 'versions', 'api_logs', 'api_tokens'], true, $columnNameAndTypeCallbacks); $application = new Application(); $application->add($populator); $application->run();
运行
php bin/command.php populator:populate
在这个设置中,AutomaticPopulatorCommand将为所有叶子表创建5个项目,然后为第2级创建25个项目,为所有后续级别创建125个项目。这可以通过 AutomaticPopulatorCommand 的参数 $countBase
和 $maxCountPerTable
进行更改。
您还可以使用 AutomaticPopulator,它允许您根据其结构或列名称为单个表创建假数据。
创建文件例如 bin/command.php
,如下所示(或将 PopulatorCommand 添加到现有的 Symfony 控制台应用程序中)
// file bin/command.php $application = new Symfony\Component\Console\Application(); $populator = new Populator\Command\PopulatorCommand(); $populator->addDatabase(new Populator\Database\Database('db_name', 'mysql:dbname=db_name;host=db_host', 'db_user', 'db_password')); $table1Populator = new Populator\Populator\AutomaticPopulator('table_1', 50); $populator->addPopulator($table1Populator); $application->add($populator); $application->run();
执行此命令后,此设置将为名为 table_1
的数据库表填充50条假记录。
php bin/command.php populator:populate