Skip to content

Commit

Permalink
Merge pull request #132 from psadaic/master
Browse files Browse the repository at this point in the history
add chunksize option
  • Loading branch information
tihomiro authored Dec 7, 2018
2 parents b166c1c + 540baad commit 360ba13
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ Example:
artisan iseed users --max=10
```

### chunksize
Optional parameter which defines the size of data chunks for each insert query.

Example:
```
artisan iseed users --chunksize=100
```

### exclude
Optional parameter which accepts comma separated list of columns that you'd like to exclude from tables that are being exported. In case of multiple tables, exclusion will be applied to all of them.

Expand Down
5 changes: 3 additions & 2 deletions src/Orangehill/Iseed/Iseed.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function readStubFile($file)
* @return bool
* @throws Orangehill\Iseed\TableNotFoundException
*/
public function generateSeed($table, $prefix=null, $suffix=null, $database = null, $max = 0, $exclude = null, $prerunEvent = null, $postrunEvent = null, $dumpAuto = true, $indexed = true, $orderBy = null, $direction = 'ASC')
public function generateSeed($table, $prefix=null, $suffix=null, $database = null, $max = 0, $chunkSize = 0, $exclude = null, $prerunEvent = null, $postrunEvent = null, $dumpAuto = true, $indexed = true, $orderBy = null, $direction = 'ASC')
{
if (!$database) {
$database = config('database.default');
Expand Down Expand Up @@ -98,7 +98,7 @@ public function generateSeed($table, $prefix=null, $suffix=null, $database = nul
$stub,
$table,
$dataArray,
null,
$chunkSize,
$prerunEvent,
$postrunEvent,
$indexed
Expand Down Expand Up @@ -223,6 +223,7 @@ public function getStubPath()
public function populateStub($class, $stub, $table, $data, $chunkSize = null, $prerunEvent = null, $postrunEvent = null, $indexed = true)
{
$chunkSize = $chunkSize ?: config('iseed::config.chunk_size');

$inserts = '';
$chunks = array_chunk($data, $chunkSize);
foreach ($chunks as $chunk) {
Expand Down
10 changes: 9 additions & 1 deletion src/Orangehill/Iseed/IseedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function fire()
}

$tables = explode(",", $this->argument('tables'));
$chunkSize = intval($this->option('max'));
$max = intval($this->option('max'));
$chunkSize = intval($this->option('chunksize'));
$exclude = explode(",", $this->option('exclude'));
$prerunEvents = explode(",", $this->option('prerun'));
$postrunEvents = explode(",", $this->option('postrun'));
Expand All @@ -66,6 +67,10 @@ public function fire()
$prefix = $this->option('classnameprefix');
$suffix = $this->option('classnamesuffix');

if ($max < 1) {
$max = null;
}

if ($chunkSize < 1) {
$chunkSize = null;
}
Expand Down Expand Up @@ -94,6 +99,7 @@ public function fire()
$prefix,
$suffix,
$this->option('database'),
$max,
$chunkSize,
$exclude,
$prerunEvent,
Expand All @@ -116,6 +122,7 @@ public function fire()
$prefix,
$suffix,
$this->option('database'),
$max,
$chunkSize,
$exclude,
$prerunEvent,
Expand Down Expand Up @@ -155,6 +162,7 @@ protected function getOptions()
array('force', null, InputOption::VALUE_NONE, 'force overwrite of all existing seed classes', null),
array('database', null, InputOption::VALUE_OPTIONAL, 'database connection', \Config::get('database.default')),
array('max', null, InputOption::VALUE_OPTIONAL, 'max number of rows', null),
array('chunksize', null, InputOption::VALUE_OPTIONAL, 'size of data chunks for each insert query', null),
array('exclude', null, InputOption::VALUE_OPTIONAL, 'exclude columns', null),
array('prerun', null, InputOption::VALUE_OPTIONAL, 'prerun event name', null),
array('postrun', null, InputOption::VALUE_OPTIONAL, 'postrun event name', null),
Expand Down

0 comments on commit 360ba13

Please sign in to comment.