Ejemplo n.º 1
0
 protected function execute()
 {
     $this->getLogger()->info("Copying data from `{$this->origin->getName()}` into `{$this->destination->getName()}`");
     while ($this->nextToInsert < $this->limit || $this->nextToInsert == 1 && $this->start == 1) {
         $query = $this->copy($this->bottom(), $this->top($this->options['stride']));
         $this->getLogger()->debug($query);
         $this->adapter->query($query);
         $this->nextToInsert = $this->top($this->options['stride']) + 1;
     }
 }
Ejemplo n.º 2
0
 /**
  * Extract the primary key of a table.
  *
  * @param \Phinx\Db\Table $table
  * @return string
  */
 public function extractPrimaryKey(\Phinx\Db\Table $table)
 {
     $tableName = $table->getName();
     $databaseName = $this->adapter->getOption('name');
     $query = implode(" ", ['SELECT `COLUMN_NAME`', 'FROM `information_schema`.`COLUMNS`', "WHERE (`TABLE_SCHEMA` = '{$databaseName}')", "AND (`TABLE_NAME` = '{$tableName}')", "AND (`COLUMN_KEY` = 'PRI');"]);
     $result = $this->adapter->query($query);
     if ($result instanceof \PDOStatement) {
         return $result->fetchColumn(0);
     }
     if (is_array($result)) {
         return $result[0];
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * Execute the switch
  */
 protected function execute()
 {
     $sqlHelper = $this->getSqlHelper();
     foreach ($this->statements() as $statement) {
         $this->adapter->query($sqlHelper->tagged($statement));
     }
 }
Ejemplo n.º 4
0
 /**
  * @return Table
  * @throws \RuntimeException
  */
 public function temporaryTable()
 {
     if ($this->destination) {
         return $this->destination;
     }
     $temporaryTableName = $this->temporaryTableName();
     if ($this->adapter->hasTable($temporaryTableName)) {
         throw new \RuntimeException("The table `{$temporaryTableName}` already exists.");
     }
     $this->getLogger()->info("Creating temporary table `{$temporaryTableName}` from `{$this->origin->getName()}`");
     $this->adapter->query("CREATE TABLE {$temporaryTableName} LIKE {$this->origin->getName()}");
     return new \Lhm\Table($temporaryTableName, [], $this->adapter);
 }
Ejemplo n.º 5
0
 /**
  * Execute the atomic rename.
  */
 protected function execute()
 {
     $retries = 0;
     while ($retries < $this->options['max_retries']) {
         $retries++;
         try {
             foreach ($this->statements() as $statement) {
                 $this->getLogger()->debug("Executing statement `{$statement}`");
                 $this->adapter->query($statement);
             }
             return;
         } catch (\Exception $e) {
             if ($this->shouldRetryException($e)) {
                 $this->getLogger()->warning($e->getMessage());
                 sleep($this->options['retry_sleep_time']);
                 //TODO log the retry
                 continue;
             }
             throw $e;
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Executes a SQL statement and returns the result as an array.
  *
  * @param string $sql SQL
  * @return array
  */
 public function query($sql)
 {
     return $this->adapter->query($sql);
 }
Ejemplo n.º 7
0
 /**
  * Executes required after migration statements
  */
 protected function after()
 {
     foreach ($this->untangle() as $statement) {
         $this->adapter->query($this->sqlHelper->tagged($statement));
     }
 }