miksir/yii2-db-faker

Fill your database table with fake data

Installs: 879

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Open Issues: 1

Type:yii2-extension

1.0.1 2016-05-02 01:31 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:09:49 UTC


README

This Yii2 command can fill your database with fake data. Useful if you need lot of fake data, 1 mil rows and more.

You can switch between different data generators (or write your own) and different database connectors.

Props:

  • you can write own sources of fake data (proxy to fzaninotto/Faker included)
  • different connectors to datbase for save data. ActiveRecord - slow but with model logic, YiiDAO - fast batch insert, TODO: postgresql COPY connector.

Generators included:

  • FakeGenerator: this is proxy to Faker and use same logic, paths and templates as yii2-faker . Read yii2-faker documentation about creating fixtures template file

Database connectors (called here as dbproviders):

  • Csv: simple csv writer
  • ActiveRecord: create model, fill with data and call ->save()
  • YiiDAO: insert data using sql (via Yii's PDO), can insert multiple rows per one insert

Installation

Use composer :)

composer require miksir/yii2-db-faker

You should configure your application as follows (usually in console.php; and you can use any alias, not only "faker"):

'controllerMap' => [
 'faker' => [
     'class' => 'MiksIr\Yii2DbFaker\FakerController',
 ],
],

Call help for current generator and dbprovider

yii faker/help

Examples

yii faker/generate --count=1000000 --dbprovider=YiiDAO generator_template=users dbprovider_table=users dbprovider_truncate=1

Truncate table users and create about 1 million rows using template from @tests/unit/templates/fixtures/users.php