Skip to content

Commit 8b1b0bd

Browse files
swissspidyclaude
andcommitted
Select the --where rows once per table, before any column is replaced
A --where condition on a column that the same run replaces was evaluated again for each column, so once one column was replaced, the next columns no longer matched it: the live run depended on the column order and made fewer replacements than the dry run reported. With more than one column, select the primary keys of the matching rows before any replacement, paging by primary key, and restrict every column's replacement and dry-run count to those keys, in chunks of 1000. Columns that share their conditions share one key list; tables without --where, and single columns, keep their existing queries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
1 parent 894ee48 commit 8b1b0bd

2 files changed

Lines changed: 251 additions & 62 deletions

File tree

‎features/search-replace-where.feature‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,51 @@ Feature: Test search-replace --where option
468468
Post foo
469469
"""
470470

471+
@require-mysql
472+
Scenario Outline: Where condition selects the rows before any column is replaced
473+
Given a WP install
474+
And I run `wp post create --post_title='Title foo' --post_content='Content foo' --porcelain`
475+
And save STDOUT as {MATCH_ID}
476+
And I run `wp post create --post_title='Other foo' --post_content='Other none' --porcelain`
477+
And save STDOUT as {OTHER_ID}
478+
479+
When I run `wp search-replace foo bar --where='<where>' --dry-run --format=count <flags>`
480+
Then STDOUT should be:
481+
"""
482+
2
483+
"""
484+
485+
When I run `wp search-replace foo bar --where='<where>' --format=count <flags>`
486+
Then STDOUT should be:
487+
"""
488+
2
489+
"""
490+
491+
When I run `wp post get {MATCH_ID} --field=title`
492+
Then STDOUT should be:
493+
"""
494+
Title bar
495+
"""
496+
497+
When I run `wp post get {MATCH_ID} --field=content`
498+
Then STDOUT should be:
499+
"""
500+
Content bar
501+
"""
502+
503+
When I run `wp post get {OTHER_ID} --field=title`
504+
Then STDOUT should be:
505+
"""
506+
Other foo
507+
"""
508+
509+
Examples:
510+
| where | flags |
511+
| posts:post_content,post_title:post_content LIKE "%foo%" | |
512+
| posts:post_content,post_title:post_content LIKE "%foo%" | --precise |
513+
| posts:post_title:post_content LIKE "%foo%";posts:post_content:post_title LIKE "%foo%" | |
514+
| posts:post_title:post_content LIKE "%foo%";posts:post_content:post_title LIKE "%foo%" | --precise |
515+
471516
Scenario: Where clause cannot be combined with an export
472517
Given a WP install
473518

0 commit comments

Comments
 (0)