Skip to content

Fix MySQL default timestamp for 5.5.5+ bwc #59805

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

Merged
merged 4 commits into from
Jul 22, 2025

Conversation

bor0
Copy link
Member

@bor0 bor0 commented Jul 20, 2025

Changes proposed in this Pull Request:

We switched to using CURRENT_TIMESTAMP in #53940. Find details in commit 9606375.

However, that caused backward compatibility issues with MySQL 5.5.5 since DEFAULT CURRENT_TIMESTAMP isn't supported.

Since we started indexing on date_created, and index creation fails on '0000-00-00 00:00:00', we use '1970-01-01 00:00:00' which seems to be another commonly used placeholder for "no data".

This makes MySQL 5.5.5+ happy, and it also makes the index happy.

Closes pcShBQ-3tn#comment-5181.

How to test the changes in this Pull Request:

  1. Install WordPress and then WooCommerce in an environment with MySQL 5.5.5.
  2. Activate WooCommerce.
  3. Expect no errors with DB creation.
  4. SHOW INDEX FROM wc_order_product_lookup should show the index on date_created

Repeat testing instructions with a more recent MySQL version.

Testing that has already taken place:

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

We switched to using `CURRENT_TIMESTAMP` in #53940.
Find details in commit 9606375.

However, that caused backward compatibility issues with MySQL 5.5.5
since `DEFAULT CURRENT_TIMESTAMP` isn't supported.

Since we started indexing on `date_created`, and index creation fails on
'0000-00-00 00:00:00', we use '1970-01-01 00:00:00' which seems to be
another commonly used placeholder for "no data".

This makes MySQL 5.5.5+ happy, and it also makes the index happy.
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jul 20, 2025
Copy link
Contributor

coderabbitai bot commented Jul 20, 2025

📝 Walkthrough

Walkthrough

The change updates the WooCommerce database schema generation to conditionally set the default value for the date_created column in the wc_order_product_lookup table based on the MySQL version. For MySQL 5.6 and above, it uses DEFAULT CURRENT_TIMESTAMP; otherwise, it uses '1970-01-01 00:00:00'. A new changelog entry was added documenting this fix for MySQL 5.5.5 compatibility. No public APIs or exported entities were altered.

Changes

File Change Summary
plugins/woocommerce/includes/class-wc-install.php Modified get_schema() to set date_created default as CURRENT_TIMESTAMP if MySQL ≥ 5.6, else '1970-01-01 00:00:00'.
plugins/woocommerce/changelog/fix-default-timestamp-mysql-compat Added a patch-level changelog entry documenting the MySQL 5.5.5 compatibility fix.

Sequence Diagram(s)

sequenceDiagram
    participant Installer as WC Installer
    participant Database as Database

    Installer->>Database: Check MySQL version
    alt MySQL ≥ 5.6
        Installer->>Database: Create wc_order_product_lookup with date_created default CURRENT_TIMESTAMP
    else MySQL < 5.6
        Installer->>Database: Create wc_order_product_lookup with date_created default '1970-01-01 00:00:00'
    end
    Database-->>Installer: Table created with appropriate default
Loading

Estimated code review effort

2 (10–30 minutes)


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 01ccee4 and 3652839.

📒 Files selected for processing (1)
  • plugins/woocommerce/includes/class-wc-install.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/woocommerce/includes/class-wc-install.php
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

github-actions bot commented Jul 20, 2025

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

Copy link
Member

@NeosinneR NeosinneR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bor0 since date_created is indexed, have you checked if this value is also being set when adding a new row or if it depends on the DEFAULT? I'm asking because if it's the latter, then there will be many rows with '1970-01-01 00:00:00' and index won't be as performant (which wouldn't be the case with CURRENT_TIMESTAMP)

@bor0
Copy link
Member Author

bor0 commented Jul 21, 2025

@NeosinneR good point.

The column's value seems to always be set here (didn't find other places where we insert), so it shouldn't be an issue.

But, there are always customizations with hooks/filters, and to be more on the safe side, I guess we can still use DEFAULT_TIMESTAMP for newer MySQL versions. Performed this change in 01ccee4

Copy link
Member

@NeosinneR NeosinneR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @bor0. I checked the wc_get_server_database_version() function and unless the $wpdb->get_var( 'SELECT VERSION()' ); fails (in which case the website has probably other issues), the 'number' should always be a string, so the version compare shouldn't fail.

@nerrad
Copy link
Contributor

nerrad commented Jul 21, 2025

Does the version check account for MariaDB usage?

@NeosinneR
Copy link
Member

Does the version check account for MariaDB usage?

@nerrad it does. datetime DEFAULT CURRENT_TIMESTAMP is supported since MariaDB 10.0. MariaDB versioning followed MySQL until 5.5 (there are no MariaDB 5.6-9.9) so just checking the >=5.6 version number regardless of engine covers both MySQL and MariaDB.

@bor0 bor0 merged commit 12d0585 into trunk Jul 22, 2025
96 of 105 checks passed
@bor0 bor0 deleted the fix/default-timestamp-mysql-compat branch July 22, 2025 12:44
@github-actions github-actions bot added this to the 10.2.0 milestone Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants