Beispiel #1
0
 /**
  * @param $child
  * @param $parent
  * @param Migration $migration
  *
  * @throws NodeNotFoundError
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public function addDependency($child, $parent, $migration)
 {
     // both parent and child need to be already in the graph
     if (!ArrayHelper::hasKey($this->nodes, $child)) {
         throw new NodeNotFoundError(sprintf('Migration %s dependencies reference nonexistent child node %s', $migration->getName(), $child));
     }
     if (!ArrayHelper::hasKey($this->nodes, $parent)) {
         throw new NodeNotFoundError(sprintf('Migration %s dependencies reference nonexistent parent node %s', $migration->getName(), $parent));
     }
     // add to the family tree of both the child and parent
     $this->getNodeFamilyTree($child)->addParent($this->nodeFamilyTree[$parent]);
     $this->getNodeFamilyTree($parent)->addChild($this->nodeFamilyTree[$child]);
 }
Beispiel #2
0
 /**
  * Converts migration object into a string and adds it to the migration file temple, ready to be written on disk.
  *
  * @return string
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public function getContent()
 {
     $imports = [];
     $stringedOperations = [];
     foreach ($this->migration->getOperations() as $op) {
         list($opString, $importString) = FormatFileContent::formatObject($op);
         array_push($stringedOperations, $opString);
         $imports = array_merge($imports, $importString);
     }
     $imports = array_unique($imports);
     $importPaths = '';
     foreach ($imports as $import) {
         $import = sprintf('use %s;', $import);
         $importPaths .= $import . PHP_EOL;
     }
     $opContent = '[' . PHP_EOL;
     foreach ($stringedOperations as $op) {
         $opContent .= sprintf("\t\t\t%s," . PHP_EOL, $op);
     }
     $opContent .= "\t\t]";
     $dependencies = $this->migration->getDependency();
     $indent = count($dependencies) <= 1 ? false : 3;
     return sprintf($this->getFileTemplate(), $importPaths, $this->migration->getName(), Tools::stringify($dependencies, $indent), $opContent);
 }
Beispiel #3
0
 /**
  * Applies the migration to the database.
  *
  * @param ProjectState $state     this is the state before the migration is applied
  * @param Migration    $migration the migration to apply
  * @param bool         $fake
  *
  * @return mixed
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public function applyMigration($state, $migration, $fake = false)
 {
     Console::stdout(sprintf(' Applying %s...', $migration->getName()));
     if (!$fake) {
         $state = $migration->apply($state, $this->schemaEditor);
     }
     $this->recorder->recordApplied(['name' => $migration->getName()]);
     if ($fake) {
         $end = Console::ansiFormat('FAKED', [Console::FG_GREEN]);
     } else {
         $end = Console::ansiFormat('OK', [Console::FG_GREEN]);
     }
     Console::stdout($end . PHP_EOL);
     return $state;
 }
Beispiel #4
0
 private function createMigration()
 {
     $migration = new Migration('auto');
     $migration->setOperations($this->generatedOperations);
     return $migration;
 }