Remove CURRENT_TIMESTAMP default on the stock table (https://github.com/woocommerce/woocommerce-blocks/pull/2590)

* Remove the default timestamp value which requires mysql 5.6.5

* Change REPLACE INTO with INSERT INTO .. ON DUPLICATE KEY UPDATE

This will allow us to set the timestamp value on first insert only.
This commit is contained in:
Mike Jolley 2020-06-01 18:40:03 +01:00 committed by GitHub
parent 576686b3d2
commit 55b8be7d76
2 changed files with 5 additions and 4 deletions

View File

@ -58,8 +58,8 @@ class Installer {
`order_id` bigint(20) NOT NULL,
`product_id` bigint(20) NOT NULL,
`stock_quantity` double NOT NULL DEFAULT 0,
`timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`expires` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`timestamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`expires` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`order_id`, `product_id`)
) $collate;
"

View File

@ -162,9 +162,10 @@ final class ReserveStock {
$result = $wpdb->query(
$wpdb->prepare(
"
REPLACE INTO {$wpdb->wc_reserved_stock} ( order_id, product_id, stock_quantity, expires )
SELECT %d, %d, %d, ( NOW() + INTERVAL %d MINUTE ) from DUAL
INSERT INTO {$wpdb->wc_reserved_stock} ( `order_id`, `product_id`, `stock_quantity`, `timestamp`, `expires` )
SELECT %d, %d, %d, NOW(), ( NOW() + INTERVAL %d MINUTE ) FROM DUAL
WHERE ( $query_for_stock FOR UPDATE ) - ( $query_for_reserved_stock FOR UPDATE ) >= %d
ON DUPLICATE KEY UPDATE `expires` = VALUES( `expires` )
",
$order->get_id(),
$product_id,