-
Notifications
You must be signed in to change notification settings - Fork 20
Add --search-replace option to vip dev-env sync sql #2613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
@copilot, I don't think we need |
Co-authored-by: sjinks <[email protected]>
Co-authored-by: sjinks <[email protected]>
Use the existing search-replace mechanism on the SQL file (via @automattic/vip-search-replace) instead of running WP-CLI search-replace after import. This matches the approach used in dev-env-import-sql and is more efficient. - Add --search-replace CLI option with array normalization - User-provided pairs are added to searchReplaceMap in generateSearchReplaceMap() - Existing runSearchReplace() method handles all replacements on SQL file - Fix early return bug in generateSearchReplaceMap() to ensure user pairs are always added Co-authored-by: sjinks <[email protected]>
You're absolutely right! I've refactored the implementation to use the SQL file search-replace approach (via The new implementation:
Changes in commit a046a41 |
|
src/commands/dev-env-sync-sql.ts
Outdated
| public _track: TrackFunction; | ||
| private _sqlDumpType?: SqlDumpType; | ||
| public sdsSiteUrls: WpSite[] = []; | ||
| private userSearchReplacePairs?: string[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot, we don't reassign this property anywhere; can we make it readonly, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Made the property readonly in commit d207359.
The property is only assigned in the constructor and never reassigned, so it can be marked as readonly for better immutability. Co-authored-by: sjinks <[email protected]>
|



Add --search-replace option to vip dev-env sync sql command
Summary
This PR adds a
--search-replace(alias-r) option to thevip dev-env sync sqlCLI command that performs search/replace operations on the SQL file during sync, matching the approach used invip dev-env import sql.Implementation Approach
Instead of running WP-CLI
search-replaceafter database import, this implementation:searchReplaceMaprunSearchReplace()method which operates on the SQL file using@automattic/vip-search-replacedev-env-import-sqlviaresolveImportPath()Changes Made
CLI (
src/bin/vip-dev-env-sync-sql.js)--search-replace/-roption with array normalizationCommand (
src/commands/dev-env-sync-sql.ts)userSearchReplacePairsreadonly property to constructoraddUserSearchReplacePairs(): Parses "search,replace" strings, validates, and adds to searchReplaceMapgenerateSearchReplaceMap()to calladdUserSearchReplacePairs()and fixed early return bugTests (
__tests__/commands/dev-env-sync-sql.ts)Benefits
Usage
Original prompt
This pull request was created as a result of the following prompt from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.