Doctrine\DBAL\Migrations\Migration::writeSqlFile PHP Méthode

writeSqlFile() public méthode

Write a migration SQL file to the given path
public writeSqlFile ( string $path, string $to = null ) : boolean
$path string The path to write the migration SQL file.
$to string The version to migrate to.
Résultat 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 ? Version::DIRECTION_DOWN : Version::DIRECTION_UP;
        $this->outputWriter->write(sprintf("-- Migrating from %s to %s\n", $from, $to));
        $sqlWriter = new SqlFileWriter($this->configuration->getMigrationsColumnName(), $this->configuration->getMigrationsTableName(), $path, $this->outputWriter);
        return $sqlWriter->write($sql, $direction);
    }

Usage Example

 public function execute(InputInterface $input, OutputInterface $output)
 {
     $version = $input->getArgument('version');
     $configuration = $this->getMigrationConfiguration($input, $output);
     $migration = new Migration($configuration);
     $this->outputHeader($configuration, $output);
     if ($path = $input->getOption('write-sql')) {
         $path = is_bool($path) ? getcwd() : $path;
         $migration->writeSqlFile($path, $version);
     } else {
         $dryRun = $input->getOption('dry-run') ? true : false;
         if ($dryRun === true) {
             $migration->migrate($version, true);
         } else {
             $noInteraction = $input->getOption('no-interaction') ? true : false;
             if ($noInteraction === true) {
                 $migration->migrate($version, $dryRun);
             } else {
                 $confirmation = $this->getHelper('dialog')->askConfirmation($output, '<question>WARNING! You are about to execute a database migration that could result in schema changes and data lost. Are you sure you wish to continue? (y/n)</question>', false);
                 if ($confirmation === true) {
                     $migration->migrate($version, $dryRun);
                 } else {
                     $output->writeln('<error>Migration cancelled!</error>');
                 }
             }
         }
     }
 }
All Usage Examples Of Doctrine\DBAL\Migrations\Migration::writeSqlFile