public function generate()
 {
     $this->tableName = preg_replace('/({{%)(\\w+)(}})?/', "\$2", $this->tableName);
     $tableName = $this->tableName;
     if ($this->useTablePrefix) {
         $tableName = "{{%{$tableName}}}";
     }
     $primary = $this->getTableFields();
     $files = [];
     $this->migrationName = Yii::$app->session->get($this->tableName) ?: false;
     $mCreate = new TableBuilderTemplateMigration(['tableName' => $tableName, 'fields' => $this->fields, 'useTablePrefix' => $this->useTablePrefix]);
     if (!$this->migrationName) {
         Yii::$app->session->set($this->tableName, $mCreate->migrationName);
     }
     $this->migrationName = $this->migrationName ?: Yii::$app->session->get($this->tableName);
     $mCreate->migrationName = $this->migrationName ?: $mCreate->migrationName;
     $files[] = new CodeFile(Yii::getAlias($this->migrationPath) . '/' . $mCreate->migrationName . '.php', $mCreate->runQuery());
     return $files;
 }
 public function generate()
 {
     $this->tableName = preg_replace('/({{%)(\\w+)(}})?/', "\$2", $this->tableName);
     $tableName = $this->tableName;
     if ($this->useTablePrefix) {
         $tableName = "{{%{$tableName}}}";
     }
     $this->getTableFields();
     if ($this->autoCreateTable && isset($_POST['generate']) || $this->forceTableCreate) {
         $this->dropIfExists = $this->forceTableCreate ? true : $this->dropIfExists;
         $tableGenerator = new TableBuilder(['tableName' => $tableName, 'fields' => $this->fields, 'useTablePrefix' => $this->useTablePrefix, 'dropOriginTable' => $this->dropIfExists]);
         $tableGenerator->runQuery(true);
     }
     $files = [];
     if ($this->migrationCreate) {
         $this->migrationName = Yii::$app->session->get($this->tableName) ?: false;
         $mCreate = new TableBuilderTemplateMigration(['tableName' => $tableName, 'fields' => $this->fields, 'useTablePrefix' => $this->useTablePrefix]);
         if (!$this->migrationName) {
             Yii::$app->session->set($this->tableName, $mCreate->migrationName);
         }
         $this->migrationName = $this->migrationName ?: Yii::$app->session->get($this->tableName);
         $mCreate->migrationName = $this->migrationName ?: $mCreate->migrationName;
         $files[] = new CodeFile(Yii::getAlias($this->migrationPath) . '/' . $mCreate->migrationName . '.php', $mCreate->runQuery());
     }
     return $files;
 }