Author: Alexey Bobkov, Samuel Georges
Inheritance: extends RainLab\Builder\Classes\BaseModel
 public function onDatabaseTableMigrationApply()
 {
     $pluginCode = new PluginCode(Request::input('plugin_code'));
     $model = new MigrationModel();
     $model->setPluginCodeObj($pluginCode);
     $model->fill($_POST);
     $operation = Input::get('operation');
     $table = Input::get('table');
     $model->scriptFileName = 'builder_table_' . $operation . '_' . $table;
     $model->makeScriptFileNameUnique();
     $codeGenerator = new TableMigrationCodeGenerator();
     $model->code = $codeGenerator->wrapMigrationCode($model->scriptFileName, $model->code, $pluginCode);
     try {
         $model->save();
     } catch (Exception $ex) {
         throw new ApplicationException($ex->getMessage());
     }
     $result = $this->controller->widget->databaseTabelList->updateList();
     $result = array_merge($result, $this->controller->widget->versionList->refreshActivePlugin());
     $result['builderResponseData'] = ['builderObjectName' => $table, 'tabId' => $this->getTabId($table), 'tabTitle' => $table, 'tableName' => $table, 'operation' => $operation, 'pluginCode' => $pluginCode->toCode()];
     return $result;
 }
 protected function loadOrCreateBaseModel($versionNumber, $options = [])
 {
     $model = new MigrationModel();
     if (isset($options['pluginCode'])) {
         $model->setPluginCode($options['pluginCode']);
     }
     if (!$versionNumber) {
         return $model;
     }
     $model->load($versionNumber);
     return $model;
 }
 protected function createMigrationObject($code, $description)
 {
     $migration = new MigrationModel();
     $migration->setPluginCodeObj($this->getPluginCodeObj());
     $migration->code = $code;
     $migration->version = $migration->getNextVersion();
     $migration->description = $description;
     return $migration;
 }