db import: Pass import file via STDIN redirection - #341
Conversation
Previously, `wp db import <file>` built a MySQL `--execute` string by interpolating the import filename into `SOURCE %s;`. Because MySQL's `--execute` flag processes client-side directives, filenames with special characters could cause syntax errors or unintended client parsing behavior. This change modifies `wp db import` to feed the SQL dump file directly to the `mysql` client via standard input redirection (` < 'filename'`). Any bulk import session optimizations (`SET unique_checks = 0; SET foreign_key_checks = 0;`) are now passed via `--init-command`, matching how session SQL modes are handled.
|
Warning Review limit reached
Next review available in: 45 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesMySQL import hardening
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates wp db import to avoid building a MySQL --execute string containing a SOURCE <file> directive, and instead feeds the dump file to mysql via STDIN redirection. This reduces risk of client-side parsing issues when import filenames contain special characters, and moves import optimizations into --init-command alongside existing SQL-mode compatibility handling.
Changes:
- Replaced
SOURCE %s;via--executewith shell input redirection (mysql < 'file') for file imports. - Moved bulk import optimization statements to
--init-command, composing with any existing--init-command. - Added Behat coverage for special-character filenames and for preventing client meta-command side effects.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/DB_Command.php |
Switches file imports to STDIN redirection and composes optimization SQL into --init-command. |
features/db-import.feature |
Adds scenarios to cover special-character filenames and client meta-command injection attempts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@features/db-import.feature`:
- Around line 387-392: Strengthen the scenario around the `When I run wp db
import` step by querying `wp_cli_meta_test` after the import and asserting the
expected inserted value, while retaining the existing success-output and
side-effect-file assertions. This must verify that the specially named SQL file
was actually processed rather than merely exiting successfully.
In `@src/DB_Command.php`:
- Around line 983-990: Update the inline documentation for the
--skip-optimization option near the command’s argument definitions to match the
implementation in the optimization SQL block: state that optimization applies to
both SQL files and STDIN imports, and that it disables unique and foreign-key
checks only rather than auto-commit.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: a5b7c418-f29b-4046-8a00-ce9b59c119ec
📒 Files selected for processing (2)
features/db-import.featuresrc/DB_Command.php
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Previously,
wp db import <file>built a MySQL--executestring by interpolating the import filename intoSOURCE %s;. Because MySQL's--executeflag processes client-side directives, filenames with special characters could cause syntax errors or unintended client parsing behavior.This change modifies
wp db importto feed the SQL dump file directly to themysqlclient via standard input redirection (< 'filename'). Any bulk import session optimizations (SET unique_checks = 0; SET foreign_key_checks = 0;) are now passed via--init-command, matching how session SQL modes are handled.Summary by CodeRabbit