/** * @param $sqlFile * @return $this */ private function processSqlFile($sqlFile) { $path = $this->projectDir . '/migrations/sql/' . $sqlFile; $this->consoleOutput('Processing sql file ' . $sqlFile . ' ... ', false); $database = $this->config->getEnvironmentVar('database'); $host = $this->config->getEnvironmentVar('host'); $port = $this->config->getEnvironmentVar('port'); $user = $this->config->getEnvironmentVar('user'); $password = $this->config->getEnvironmentVar('password'); if (!$this->pgPassChecked) { PgPass::check($host, $port, $database, $user, $password); $this->pgPassChecked = true; } $cmd = self::PSQL_CMD . ' -U ' . $user . ' -h ' . $host . ' -p ' . $port . ' -d ' . $database . ' < ' . $path . ' 2>&1'; $output = []; $status = null; exec($cmd, $output, $status); $output = implode(PHP_EOL, $output); $resultWrittenMsg = sprintf(' - result written to %s%s%s', $this->getConfig('log_dir'), $this->env, PHP_EOL); if (empty($status)) { $this->getAdapter()->setApplied($path); $this->log($sqlFile, $output, false); $this->consoleOutput('done.')->consoleOutput($resultWrittenMsg); return $this; } $this->log($sqlFile, $output, true); $this->consoleOutput('failed.')->consoleOutput($resultWrittenMsg); throw new RuntimeException(sprintf('Error while processing sql file %s', $sqlFile)); }