diff --git a/README.md b/README.md index 19dbb50..8d9b4fe 100755 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/Orangehill/Iseed/Iseed.php b/src/Orangehill/Iseed/Iseed.php index 4ac8f7c..26eb5c9 100644 --- a/src/Orangehill/Iseed/Iseed.php +++ b/src/Orangehill/Iseed/Iseed.php @@ -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) { diff --git a/src/Orangehill/Iseed/IseedCommand.php b/src/Orangehill/Iseed/IseedCommand.php index e635e05..58517ec 100755 --- a/src/Orangehill/Iseed/IseedCommand.php +++ b/src/Orangehill/Iseed/IseedCommand.php @@ -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),