public function generate($databaseName, $size, $batchSize = 1000)
 {
     $this->getConnection()->query(sprintf('USE %s', $databaseName));
     $this->reset();
     $scopes = array_keys($this->scopeFaker);
     $numberOfScopes = count($scopes);
     $currentBatch = 0;
     $createdRecords = 0;
     while ($size > $createdRecords) {
         if ($currentBatch >= $batchSize) {
             $this->flush();
             $currentBatch = 0;
         }
         $createdRecords++;
         $currentBatch++;
         $code = $this->faker->uuid;
         $this->batch['entity'][$code] = ['code' => $code];
         $this->generateAttributes($this->faker, $this->attribute->getAll(), $code, 0);
         if ($this->faker->boolean(66)) {
             $currentScopes = $this->faker->randomElements($scopes, $this->faker->numberBetween(1, $numberOfScopes));
             foreach ($currentScopes as $scopeCode) {
                 $this->generateAttributes($this->scopeFaker[$scopeCode], $this->attribute->getAllScopeAware(), $code, $this->scope->getId($scopeCode));
             }
         }
     }
     if ($currentBatch > 0) {
         $this->flush();
     }
     return $this;
 }
 public function limitFlatActive(Select $select, $alias = 'main')
 {
     $select->join(['flat' => $this->getTable('entity_flat')], $alias . '.entity_id = flat.entity_id', []);
     $select->where('flat.scope_id = ?', $this->scope->getId($this->scopeCode));
     $select->where('flat.is_active = ?', 1);
     return $this;
 }