Example #1
0
 /**
  * Executor constructor.
  *
  * @param Connection $connection
  */
 public function __construct($connection)
 {
     $this->connection = $connection;
     $this->schemaEditor = SchemaEditor::createObject($connection);
     $this->loader = Loader::createObject($connection);
     $this->recorder = Recorder::createObject($connection);
 }
Example #2
0
 /**
  * Does the actual alteration of the model table.
  *
  * @param SchemaEditor $schemaEditor
  * @param ProjectState $fromState
  * @param ProjectState $toState
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 private function _alterModelTable($schemaEditor, $fromState, $toState)
 {
     $toModel = $toState->getRegistry()->getModel($this->name);
     if ($this->allowMigrateModel($schemaEditor->connection, $toModel)) {
         $fromModel = $fromState->getRegistry()->getModel($this->name);
         $schemaEditor->alterDbTable($toModel, $fromModel->meta->dbTable, $toModel->meta->dbTable);
         // Rename M2M fields whose name is based on this model's db_table
         /** @var $newField ManyToManyField */
         /* @var $oldField ManyToManyField */
         foreach ($toModel->meta->localManyToMany as $newName => $newField) {
             foreach ($fromModel->meta->localManyToMany as $oldName => $oldField) {
                 if ($newName === $oldName) {
                     $schemaEditor->alterDbTable($newField->relation->through, $oldField->relation->through->meta->dbTable, $newField->relation->through->meta->dbTable);
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * Does the actual field alteration.
  *
  * @param SchemaEditor $schemaEditor
  * @param ProjectState $fromState
  * @param ProjectState $toState
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 private function _alterField($schemaEditor, $fromState, $toState)
 {
     $toModel = $toState->getRegistry()->getModel($this->modelName);
     if ($this->allowMigrateModel($schemaEditor->connection, $toModel)) {
         $fromModel = $fromState->getRegistry()->getModel($this->modelName);
         $fromField = $fromModel->meta->getField($this->name);
         $toField = $toModel->meta->getField($this->name);
         if (false === $this->preserveDefault) {
             $toField->default = $this->field->default;
         }
         $schemaEditor->alterField($fromModel, $fromField, $toField);
         if (false === $this->preserveDefault) {
             $toField->default = NOT_PROVIDED;
         }
     }
 }