Пример #1
0
 /**
  * Write a migration SQL file to the given path
  *
  * @param string $path The path to write the migration SQL file.
  * @param string $to   The version to migrate to.
  *
  * @return boolean $written
  */
 public function writeSqlFile($path, $to = null)
 {
     $sql = $this->getSql($to);
     $from = $this->configuration->getCurrentVersion();
     if ($to === null) {
         $to = $this->configuration->getLatestVersion();
     }
     $direction = $from > $to ? 'down' : 'up';
     $this->outputWriter->write(sprintf("# Migrating from %s to %s\n", $from, $to));
     $sqlWriter = new SqlFileWriter($this->configuration->getMigrationsTableName(), $path, $this->outputWriter);
     return $sqlWriter->write($sql, $direction);
 }
Пример #2
0
 /**
  * @param $path
  * @param $direction
  * @param array $queries
  * @param $withOw
  *
  * @dataProvider writeProvider
  */
 public function testWrite($path, $direction, array $queries, $withOw)
 {
     if ($withOw) {
         $instance = new SqlFileWriter('test', $path, $this->ow);
         $this->ow->shouldReceive('write')->with(m::type('string'))->once();
     } else {
         $instance = new SqlFileWriter('test', $path);
     }
     $instance->write($queries, $direction);
     // file content tests & cleanup
     $files = array();
     if (is_dir($path)) {
         $files = glob(realpath($path) . '/*.sql');
     } elseif (is_file($path)) {
         $files = array($path);
     }
     foreach ($files as $file) {
         $contents = file_get_contents($file);
         $this->assertNotEmpty($contents);
         unlink($file);
     }
 }
Пример #3
0
 /**
  * Write a migration SQL file to the given path
  *
  * @param string $path      The path to write the migration SQL file.
  * @param string $direction The direction to execute.
  *
  * @return boolean $written
  */
 public function writeSqlFile($path, $direction = 'up')
 {
     $queries = $this->execute($direction, true);
     $this->outputWriter->write("\n# Version " . $this->version . "\n");
     $sqlQueries = [$this->version => $queries];
     $sqlWriter = new SqlFileWriter($this->configuration->getMigrationsTableName(), $path, $this->outputWriter);
     return $sqlWriter->write($sqlQueries, $direction);
 }
Пример #4
0
 /**
  * Write a migration SQL file to the given path
  *
  * @param string $path      The path to write the migration SQL file.
  * @param string $direction The direction to execute.
  *
  * @return boolean $written
  */
 public function writeSqlFile($path, $direction = self::DIRECTION_UP)
 {
     $queries = $this->execute($direction, true);
     if (!empty($this->params)) {
         throw MigrationException::migrationNotConvertibleToSql($this->class);
     }
     $this->outputWriter->write("\n-- Version " . $this->version . "\n");
     $sqlQueries = [$this->version => $queries];
     $sqlWriter = new SqlFileWriter($this->configuration->getMigrationsColumnName(), $this->configuration->getMigrationsTableName(), $path, $this->outputWriter);
     return $sqlWriter->write($sqlQueries, $direction);
 }