mysqldump-php icon indicating copy to clipboard operation
mysqldump-php copied to clipboard

Add support for --replace option (offering to help)

Open martinjoiner opened this issue 6 years ago • 6 comments

It's a niche option that not many people use so I understand why it's not currently implemented but the --replace option that writes "REPLACE INTO...." instead of "INSERT INTO..." would have been handy for the project I am working on right now. (I had to do a find-and-replace on the generated dump file which feels a bit hacky)

Here's the MySQL doc page: https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html#option_mysqldump_replace

I am happy to make a pull request with changes to code + documentation + tests if the maintainer approves.

martinjoiner avatar Sep 02 '19 13:09 martinjoiner

Of course I would approve, I also think it could be very useful, but never needed.

Thanks in advance!

ifsnop avatar Sep 02 '19 14:09 ifsnop

Cool. I have started work on this. Can I just ask, what is the reason for all the class definitions being in 1 file? I see this needs to remain compatible with PHP 5.3 which is slightly unfamiliar to me given that I've been working in PHP 7.2 for the past few years. I will be revising my knowledge of the limitations of the older versions.

martinjoiner avatar Sep 03 '19 09:09 martinjoiner

I hate sticking to standards so old, but mysqldump-php has to be easy to deploy. It is still used in very old hosting sites (think in the oldest wordpress site you could imagine).

I don't want to impose the need to upload a zip file and decompress it's contents in such fragile environments.

Hope you understand.

ifsnop avatar Sep 03 '19 11:09 ifsnop

Of course! I expected that there would be a very good reason for keeping them all in a single file.

I am breaking the code that creates the statements into smaller methods, making the code more modulated so that little chunks of functionality can be unit tested individually for specific expectations.

For example, with the particular feature that I am adding we only need to know that the insert statements use the word "REPLACE" instead of "INSERT" when the option is truthy, we don't need to re-test every character of the whole dump file again as you already have lots of other good tests in place to check that stuff.

I'll probably finish the work over the weekend and send a PR next week.

martinjoiner avatar Sep 03 '19 13:09 martinjoiner

Can I ask how you run the PHPUnit tests locally when developing? I'm having trouble checking my work by running the existing tests. I see that the Travis config looks super neat and it just rolls through loads of boxes running different versions of PHP, running the full test suite in each box. Is there an easy way of running the suite in just 1 version of PHP locally or should I build a VM?

martinjoiner avatar Oct 07 '19 09:10 martinjoiner

Is there an easy way of running the suite in just 1 version of PHP locally or should I build a VM?

You can execute the testing script (tests/tests.sh) and it will run with your current PHP and mysql version. There is also a script to create the db user and grant him permissions.

However, you could commit to your own fork, and it will do all the testing.

ifsnop avatar Oct 07 '19 12:10 ifsnop