/** * @throws \RuntimeException */ protected function validate() { if ($this->adapter->hasTable($this->origin->getName()) && $this->adapter->hasTable($this->destination->getName())) { return; } throw new \RuntimeException("Table `{$this->origin->getName()}` and `{$this->destination->getName()}` must exist."); }
/** * @param integer $lowest * @param integer $highest * @return string */ protected function copy($lowest, $highest) { $originName = $this->adapter->quoteTableName($this->origin->getName()); $destinationName = $this->adapter->quoteTableName($this->destination->getName()); $destinationColumns = implode(',', $this->sqlHelper->quoteColumns($this->intersection->destination())); $originColumns = implode(',', $this->sqlHelper->typedColumns($originName, $this->sqlHelper->quoteColumns($this->intersection->origin()))); return implode(" ", ["INSERT IGNORE INTO {$destinationName} ({$destinationColumns})", "SELECT {$originColumns} FROM {$originName}", "WHERE {$originName}.{$this->primaryKey} BETWEEN {$lowest} AND {$highest}"]); }
/** * Returns the temporary table name. * @return string */ public function temporaryTableName() { return "lhmn_{$this->origin->getName()}"; }
public function testItRenamesDestinationToOrigin() { $this->assertTrue($this->adapter->hasTable($this->destination->getName())); $this->switcher->run(); $this->assertFalse($this->adapter->hasTable($this->destination->getName())); }
/** * @param string $type * @return string */ protected function trigger($type) { return "lhmt_{$type}_{$this->origin->getName()}"; }