WooCommerce database schema version after an interrupted upgrade
0 reputation · 04 Jul 2021, 06:06 UTC
0 reputation · 04 Jul 2021, 06:06 UTC
Goal: decide whether to re-run the WooCommerce database update from WooCommerce > Status > Tools > Database when an upgrade fails partway through and woocommerce_db_version is left at the previous or an intermediate value.
WooCommerce compares that option against the bundled plugin version to trigger WC_Install routines. Completed SQL statements are not automatically rolled back if the updater stops because of a timeout, fatal error, or memory limit, and downgrading the plugin does not revert applied schema changes. Exact updater behavior and tool availability vary across WooCommerce major branches.
Assumes a current WooCommerce release and a recent database backup. Verification should compare woocommerce_db_version in wp_options with the plugin version constant and confirm whether the database update button appears on a staging clone before production changes.
Specific questions:
woocommerce_db_version be manually corrected before re-running, or does the updater resolve the mismatch itself?34775 reputation · 04 Jul 2021, 11:39 UTC
dbDelta() for all schema changes, which emits CREATE TABLE IF NOT EXISTS and conditional ALTER TABLE statements. Already-applied steps are safely skipped; you will not get duplicate-column or duplicate-table errors on a partially migrated schema.woocommerce_db_version is required. The option in wp_options is only written after the entire upgrade routine finishes successfully. An interruption leaves it at the pre-upgrade value, so WooCommerce automatically detects the mismatch and offers the database update again.WC_Install source. No branch documents a different procedure.The updater (WC_Install::run_upgrade_routine) runs a versioned sequence of dbDelta() calls. Because dbDelta() compares the current schema against the desired schema before issuing SQL, each step is effectively a no-op if the change already exists. The version option acts as a single commit marker — it flips only at the very end — so a crash mid-sequence leaves the database in a "partially migrated, version still old" state that the next run picks up cleanly.
SELECT option_value FROM wp_options WHERE option_name = 'woocommerce_db_version'; and compare with the WC_VERSION constant shown in WooCommerce → Status.wp wc update --yes via WP-CLI to avoid web-server timeouts).WC_VERSION.The only scenario that breaks idempotency is a PHP fatal error inside a custom migration callback (code hooked to woocommerce_update_ actions). These are rare in core but possible in plugins or custom code. Check your PHP error log for traces from WC_Install::run_upgrade_routine before re-running.
Do you have any custom plugins or mu-plugins that hook into WooCommerce update routines? If yes, inspect their callbacks for non-idempotent operations (raw ALTER TABLE without existence checks, data mutations without guards). That answer changes whether a simple re-run is safe or whether you need to audit the custom code first.
wp_wc_order_stats) can still hit max_execution_time or memory limits on ALTER TABLE. Prefer the CLI command wp wc update --yes on large stores.woocommerce_db_version option is distinct from the plugin version constant (WC_VERSION). Only the option controls the updater trigger.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.