Skip to content

feat: db push prefix-safety + URL remap, sync mirror/webroot, exec shell & MOTD fix#4

Merged
vikasiwp merged 4 commits into
mainfrom
fix/cli-feedback-db-sync-exec
Jun 23, 2026
Merged

feat: db push prefix-safety + URL remap, sync mirror/webroot, exec shell & MOTD fix#4
vikasiwp merged 4 commits into
mainfrom
fix/cli-feedback-db-sync-exec

Conversation

@vikasiwp

Copy link
Copy Markdown
Contributor

Addresses validated feedback from a real LocalWP → cloud mirror-overwrite workflow (each item was checked against the source and adversarially re-reviewed before implementing).

Changes

Feedback Change
db push silently accepts a table-prefix mismatch (High, data-safety) Detects when the dump's prefix ≠ the remote site's $table_prefix; warns loudly and offers to rewrite. --rewrite-prefix remaps the dump's table identifiers (streamed; leaves data values untouched) and, post-import, remaps the prefix-bound role/capability keys ({prefix}capabilities, {prefix}user_level, {prefix}user_roles) so admin login survives. Under --force/--json it warns and proceeds (back-compat).
db push doesn't rewrite URLs --search-replace <from> <to> runs serialization-safe wp search-replace --all-tables after import.
MOTD leaks into wp/exec stdout Emits a unique marker before the remote command and slices stdout after it — clean output in both text and --json modes. Exit code unaffected.
exec runs argv with no shell; misleading help exec --shell '<cmdline>' wraps args in bash -lc (pipes/;/>/globs). Replaced the deceptive -- ps aux | grep php example (which piped locally) and added a metacharacter note.
sync push is additive only --delete on push/pull (true mirror), confirmation-guarded (--yes to skip, --dry-run to preview); additive stays default; errors clearly on Windows/SFTP.
No transfer outside wp-content --remote-path <path> / --webroot on sync push/pull.
Inconsistent site identifier versions create echoes the restore/list hint with the identifier you typed.

Implementation notes

  • Pure logic extracted into side-effect-free, directly-testable lib modules: lib/sql-dump.ts (prefix detect/rewrite), lib/remote-command.ts (command build + MOTD slice), and buildRemotePathlib/paths.ts — matching the existing paths.ts/local-instance.ts pattern.
  • The --rewrite-prefix flow reuses the same role/capability-key remap that local push --with-db already does.

Tests

  • 27 new unit tests (sql-dump, remote-command, sync-remote-path), tsc clean, help output verified.
  • Pre-existing suite failures (sqlite-to-mysql) are environmental — better-sqlite3 built against a different Node version (npm rebuild better-sqlite3), unrelated to this PR.

Deliberately deferred

  • exec stdin forwarding — needs a transport redesign (spawnSync's input already owns ssh's stdin to deliver the command); separate, riskier change.
  • A narrow --json argv-strip bug in index.ts (a bare --json meant for WP-CLI is stripped globally) — left untouched to keep scope tight.

🤖 Generated with Claude Code

…ec shell & MOTD fix

Addresses validated feedback from a LocalWP -> cloud mirror-overwrite workflow:

- db push: detect table-prefix mismatch (warn + offer rewrite); --rewrite-prefix
  remaps dump table identifiers + role/capability keys so admin login survives
- db push: --search-replace <from> <to> (serialization-safe, runs post-import)
- wp/exec: strip server login banner/MOTD from stdout and the --json payload
- exec: --shell '<cmdline>' for pipes/;/>/globs; fix misleading help example
- sync push/pull: --delete (mirror, confirm-guarded) + --remote-path/--webroot
- versions create: echo the identifier the user typed in restore/list hints

Pure helpers extracted to lib/sql-dump.ts, lib/remote-command.ts, lib/paths.ts
with 27 new unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@claude

claude Bot commented Jun 23, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

Re-test feedback (#11, #12):
- db push success summary prints readable "from -> to" for rewrote_prefix and
  search_replaced instead of "[object Object]"
- --search-replace now passes --skip-columns=guid (post GUIDs are permanent
  identifiers, not links — WP best practice); same applied to local push --with-db

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@claude

claude Bot commented Jun 23, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@vikasprogrammer

Copy link
Copy Markdown
Contributor

Re-test update (2026-06-23)

The tester rebuilt from this branch and re-ran against a real LocalWP → cloud mirror-overwrite. 7 of 10 validated fixed, including the High-severity #1 (real push: detected mismatch, rewrote prefix, remapped cap keys, 0 orphan tables) and #6 (235 replacements, 0 residual localhost).

Two new minor findings from the re-test are now fixed in 205f4aa:

  • #11 (cosmetic): db push success summary printed rewrote_prefix: [object Object] → now prints wp_ -> iwpa4c7_ and from -> to for search-replace.
  • #12: --search-replace rewrote guid (216 of 235 replacements were posts.guid) → now passes --skip-columns=guid (WP best practice); same applied to local push --with-db.

Remaining from the original 10:

Closes the last open item from the CLI feedback. `exec --stdin` forwards the
local process's stdin to the remote command (uploads, restore pipes,
`tar czf - dir | exec --stdin 'tar xzf -'`).

Implemented as an explicit opt-in flag so the default wp/exec path is unchanged
(no regression risk to the command-via-stdin delivery the servers expect). The
--stdin path passes the command as an ssh argument — freeing stdin to stream —
and as a side effect runs a non-login remote shell, so it emits no MOTD. Text
mode inherits stdio for binary-safe real-time passthrough; JSON mode captures.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@claude

claude Bot commented Jun 23, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

Finalize CHANGELOG header and bump version for the CLI-feedback fixes
(db push prefix-safety/--search-replace, MOTD strip, exec --shell/--stdin,
sync --delete/--webroot/--remote-path, versions identifier echo).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vikasiwp vikasiwp merged commit 59e9147 into main Jun 23, 2026
1 check failed
@claude

claude Bot commented Jun 23, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants