Add debug option to show raw SQL
Sometimes when trying to run migration and failing for weird database errors it's hard to debug the problem without knowing what exact SQL is being issued against the server. The --verbose option shows what Phinx is trying to do, but not exactly how.
Maybe another option -vv or --debug could show the commands sent to the server?
:+1:
or --show-sql?
Would be great. Would have some common functionality with my feature request #102
I've had to do the same myself, and it is pretty simple to get the final query that is executed.
In Db/Adapter/PdoAdapter.php
<?php
public function execute($sql)
{
return $this->getConnection()->exec($sql);
}
replace with
<?php
public function execute($sql)
{
if (OutputInterface::VERBOSITY_VERBOSE === $this->getOutput()->getVerbosity()) {
$this->getOutput()->writeln($sql);
}
return $this->getConnection()->exec($sql);
}
This will obviously show the raw queries when you use the --verbose command, but another flag would most likely be more appropriate.
+1
+1
+1 But what about non-PDO Adapters? I know that all of the adapters are extending from PDOAdapter, but what if we want to add a Cassandra Adapter? We will have to copy that implementation, make sense?
+1 Want to see steps of migration. They may be slow.
+1
+1
Maybe also report back the number of rows affected/inserted too.
+1
+1
I'd be happy with the verbose flag being used if the intent is that you occasionally (i.e. during debugging/building) you want to see the queries.
I've got a PR for showing the migration start/end times. Using -v.
For this issue, a -v (w|c|sh)ould show the query, with -vv showing maybe the response times and rows affected counts.
Considering Symfony/Console already provides this option, it would seem pointless creating another for something that is of occasional use.
Having said that, a --query-log[=filename] option would also make sense. With the filename being defaulted to something like phinx_2015-10-22_17-46-17_command.sql, where command is migrate or rollback. So you could see a list of SQL files, in order of execution, containing JUST the SQL statements executed.
+1
+1
this seems to be somewhat related to https://github.com/robmorgan/phinx/issues/567 (ie. as both features would show the SQL statements, the one here running them after and that other exiting without running them)
+1
+1
+1
+1
+1