Skip to content

Commit 01ccee4

Browse files
committed
Use DEFAULT CURRENT_TIMESTAMP when it is possible to do so
1 parent 145e48b commit 01ccee4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

plugins/woocommerce/includes/class-wc-install.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,13 @@ private static function get_schema() {
16041604
self::should_enable_hpos_for_new_shop();
16051605
$hpos_table_schema = $hpos_enabled ? wc_get_container()->get( OrdersTableDataStore::class )->get_database_schema() : '';
16061606

1607+
$mysql_version = wc_get_server_database_version()['number'];
1608+
if ( version_compare( $mysql_version, '5.6', '>=' ) ) {
1609+
$datetime_default = "DEFAULT CURRENT_TIMESTAMP";
1610+
} else {
1611+
$datetime_default = "DEFAULT '1970-01-01 00:00:00'";
1612+
}
1613+
16071614
$tables = "
16081615
CREATE TABLE {$wpdb->prefix}woocommerce_sessions (
16091616
session_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
@@ -1860,7 +1867,7 @@ private static function get_schema() {
18601867
product_id bigint(20) unsigned NOT NULL,
18611868
variation_id bigint(20) unsigned NOT NULL,
18621869
customer_id bigint(20) unsigned NULL,
1863-
date_created datetime DEFAULT '1970-01-01 00:00:00' NOT NULL,
1870+
date_created datetime $datetime_default NOT NULL,
18641871
product_qty int(11) NOT NULL,
18651872
product_net_revenue double DEFAULT 0 NOT NULL,
18661873
product_gross_revenue double DEFAULT 0 NOT NULL,

0 commit comments

Comments
 (0)