Repository navigation
Restore session variables with COALESCE in exported dumps, so split imports keep the current value - #42
Conversation
…, so importers that split statements across connections don't restore NULL Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
JanJakes
left a comment
There was a problem hiding this comment.
@youknowriad Checking 👀
Could we keep the mysqldump behavior and make the restore safer? For example, SET SQL_MODE=COALESCE(@OLD_SQL_MODE, @@SQL_MODE); would restore the original mode on the same connection and keep the current mode on a fresh one. We could do the same for FOREIGN_KEY_CHECKS.
Two questions about Jetpack Backup’s restore:
- Would a standard
mysqldumpexport hit the same error if Jetpack runs its footer on a different connection from its header? - When a table spans several chunks, does Jetpack reapply
SQL_MODEandFOREIGN_KEY_CHECKS=0on each new connection? If it doesn’t, could anINSERTin a later chunk fail before we even reach the footer?
I’d prefer to stay close to mysqldump here. With COALESCE, I guess that's close enough, but we'd need to document why it differs from mysqldump.
…ements across connections keep the current value Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Good call, I switched to
|
…st try (#6185) ## Related issues - Related to Automattic/wp-cli-sqlite-command#42 - Follow-up to #6103 ## How AI was used in this PR Claude investigated the failed fvm.house push in the Jetpack Backup restore logs, wrote the upstream fix, and ran the test pushes below. I reviewed the change and the results. ## Proposed Changes - Pushes from Studio builds with `wp-cli-sqlite-command` v1.1.11 (from #6103, in 2.4.0) fail Jetpack Backup's first restore method. The dump ends with `SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;`. Jetpack runs a dump's statements over several connections, so the variable is NULL by the time that statement runs, and MySQL rejects it (error 1231). - Jetpack then restarts the restore with its slower fallback method. That fallback usually succeeds but adds hours on large sites, and it sometimes fails, as on fvm.house, where the push ended with "Importing SQL dump" / "All enabled restore methods failed!". - v1.1.12 restores the session variables with `COALESCE`, so the dump also loads when its statements run over several connections. This PR moves the fallback version to v1.1.12, like #6103 did for v1.1.11. Builds already download the latest release, so this mainly keeps the fallback in step. ## Testing Instructions - `npm run postinstall && npm run cli:build`, then check that `apps/cli/dist/cli/wp-files/sqlite-command/version` is `v1.1.12`. - Push a local site to a WordPress.com test site: `node apps/cli/dist/cli/main.mjs push --path <site> --remote-site <id>`. - In log2logstash, the site's restore should log `DPC_RESTORE_SUCCEEDED` with no fallback. With v1.1.11 the first method failed on the statement above. I did this with a WooCommerce site pushed to a WordPress.com test site, which failed the first method with v1.1.11 the day before. The full push (files and database) restored on the first method: 6,017 items, 0 errors, about 5 minutes end to end. ## Pre-merge Checklist - [ ] Have you checked for TypeScript, React or other console errors? 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Exported dumps keep the
mysqldumpheader from #40, but the footer now falls back to the current value when the saved one is missing:Why
A user variable only lives in the connection that set it, and some importers don't run a dump in a single connection. Jetpack Backup's restore, which WordPress Studio's push to WordPress.com goes through, splits each table's statements into several batches. It sends those batches to the site over separate requests, each with its own MySQL connection. So
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;runs where the variable is NULL, and MySQL rejects it with error 1231 (Variable 'foreign_key_checks' can't be set to the value of 'NULL').Since v1.1.11, Jetpack's first restore method fails on Studio pushes. The fallback then restarts the whole restore, which adds hours on large sites and sometimes fails too.
With
COALESCE, a dump imported over one connection restores the original values exactly asmysqldumpdoes. On a new connection, the footer keeps that connection's current values.Testing
COALESCEstatements.WP_CLI_TEST_DBTYPE=sqlite vendor/bin/behat: all scenarios pass.composer phpcsandcomposer lintare clean.🤖 Generated with Claude Code