Esempio n. 1
0
 /**
  * @param AdapterInterface $adapter
  * @param \Phinx\Db\Table $origin
  * @param \Lhm\Table $destination
  * @param SqlHelper $sqlHelper
  * @param array $options
  *                      - `stride`
  *                          Size of chunk ( defaults to 2000 )
  */
 public function __construct(AdapterInterface $adapter, \Phinx\Db\Table $origin, \Lhm\Table $destination, SqlHelper $sqlHelper = null, array $options = [])
 {
     $this->adapter = $adapter;
     $this->origin = $origin;
     $this->destination = $destination;
     $this->sqlHelper = $sqlHelper ?: new SqlHelper($this->adapter);
     $this->options = $options + ['stride' => 2000];
     $this->primaryKey = $this->adapter->quoteColumnName($this->sqlHelper->extractPrimaryKey($this->origin));
     $this->nextToInsert = $this->start = $this->selectStart();
     $this->limit = $this->selectLimit();
     $this->intersection = new Intersection($this->origin, $this->destination);
 }
Esempio n. 2
0
 /**
  * @return string
  */
 protected function createDeleteTrigger()
 {
     $name = $this->trigger('delete');
     $primaryKey = $this->sqlHelper->extractPrimaryKey($this->origin);
     if (empty($primaryKey)) {
         throw new \RuntimeException("Table `{$this->origin->getName()}` does not have a primary key.");
     }
     $primaryKey = $this->sqlHelper->quoteColumn($primaryKey);
     $originName = $this->adapter->quoteTableName($this->origin->getName());
     $destinationName = $this->adapter->quoteTableName($this->destination->getName());
     return implode("\n ", ["CREATE TRIGGER {$name}", "AFTER DELETE ON {$originName} FOR EACH ROW", "DELETE IGNORE FROM {$destinationName} {$this->sqlHelper->annotation()}", "WHERE {$destinationName}.{$primaryKey} = OLD.{$primaryKey}"]);
 }