phinx icon indicating copy to clipboard operation
phinx copied to clipboard

Add debug option to show raw SQL

Open igorsantos07 opened this issue 13 years ago • 30 comments

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?

igorsantos07 avatar May 30 '13 19:05 igorsantos07

:+1: or --show-sql?

czogori avatar Jun 01 '13 22:06 czogori

Would be great. Would have some common functionality with my feature request #102

joshribakoff avatar Jul 06 '13 04:07 joshribakoff

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.

tomzx avatar Jul 09 '13 03:07 tomzx

+1

artptr avatar Dec 29 '13 17:12 artptr

+1

robertmarsal avatar Jul 17 '14 16:07 robertmarsal

+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?

mcapodacqua avatar Jul 21 '14 12:07 mcapodacqua

+1 Want to see steps of migration. They may be slow.

tinpansoul avatar Feb 06 '15 08:02 tinpansoul

+1

valkirilov avatar May 13 '15 06:05 valkirilov

+1

Maybe also report back the number of rows affected/inserted too.

rquadling avatar May 13 '15 09:05 rquadling

+1

jiMuBao avatar Sep 23 '15 21:09 jiMuBao

+1

Keloo avatar Oct 22 '15 14:10 Keloo

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.

rquadling avatar Oct 22 '15 16:10 rquadling

+1

TiGR avatar Dec 31 '15 14:12 TiGR

+1

ghost avatar Jan 07 '16 16:01 ghost

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)

ghost avatar Jan 07 '16 17:01 ghost

+1

c10ce avatar Jan 25 '16 18:01 c10ce

+1

SanderSander avatar Feb 01 '16 12:02 SanderSander

+1

mfacenet avatar Feb 02 '16 17:02 mfacenet

+1

FlorianH avatar Mar 04 '16 16:03 FlorianH

+1

rewmike avatar Mar 29 '16 17:03 rewmike