Skip to content
Permalink
Browse files

add chunksize option

  • Loading branch information...
psadaic committed Dec 6, 2018
1 parent b166c1c commit 540baadac692ed54049a8472c6ede45cde9a0e4e
Showing with 20 additions and 3 deletions.
  1. +8 −0 README.md
  2. +3 −2 src/Orangehill/Iseed/Iseed.php
  3. +9 −1 src/Orangehill/Iseed/IseedCommand.php
@@ -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.

@@ -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');
@@ -98,7 +98,7 @@ public function generateSeed($table, $prefix=null, $suffix=null, $database = nul
$stub,
$table,
$dataArray,
null,
$chunkSize,
$prerunEvent,
$postrunEvent,
$indexed
@@ -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) {
@@ -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'));
@@ -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;
}
@@ -94,6 +99,7 @@ public function fire()
$prefix,
$suffix,
$this->option('database'),
$max,
$chunkSize,
$exclude,
$prerunEvent,
@@ -116,6 +122,7 @@ public function fire()
$prefix,
$suffix,
$this->option('database'),
$max,
$chunkSize,
$exclude,
$prerunEvent,
@@ -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),

0 comments on commit 540baad

Please sign in to comment.
You can’t perform that action at this time.