Skip to content

Conversation

@Konamiman
Copy link
Contributor

@Konamiman Konamiman commented Apr 20, 2022

All Submissions:

Changes proposed in this Pull Request:

We have decided to use placeholder entries in the posts table as the mechanism to prevent posts/orders id conflicts (#32086 (comment)), so this pull request implements the required changes:

  • The post_id column is removed from the orders table.
    • The column is removed from the schema, but no database migration is provided to remove it if the table already exists. That's because the feature is in early stages of development and few people outside Automattic will have created the orders table already. Also the column continuing to be in place isn't harmful in any way.
  • The SQL queries used to count the out of sync orders and to get the ids of these orders are adjusted according to the new mechanism.

Note: All the tests in WPPostToCOTMigratorTest are temporarily skipped because the tested code is still not adapted to the removal of the post_id column; they need to be "de-skipped" after (or as part of) #32700.

Closes #32663.
Closes #32665.

How to test the changes in this Pull Request:

Same testing instructions as in #32062. However, the SQL queries that create data for testing are now these (note that this time data needs to be created both in the new orders table and in the posts table):

/* Create some synchronized entries in orders table from existing orders in posts table */
INSERT INTO wp_wc_orders (id,date_created_gmt,date_updated_gmt)
SELECT ID,post_date_gmt,post_modified_gmt from wp_posts 
WHERE post_type='shop_order' AND post_status != 'auto-draft'
ORDER BY id DESC LIMIT 10;

/* Force some of the synchronized entries to be out of sync */
UPDATE wp_wc_orders SET date_updated_gmt=now() LIMIT 2;

/* Create some placeholder entries in posts table and the corresponding authotitative entries in the orders table
(LIMIT in second INSERT should be equal to the number of VALUES rows in the first INSERT)*/
INSERT INTO wp_posts (post_author,post_date,post_date_gmt,post_content,post_title,post_excerpt,post_status,comment_status,ping_status,post_password,post_name,to_ping,pinged,post_modified,post_modified_gmt,post_content_filtered,post_parent,guid,menu_order,post_type,post_mime_type,comment_count)
VALUES
(1,current_timestamp(),current_timestamp(),'','','','','','','','','','',current_timestamp(),current_timestamp(),'',0,'',0,('shop_order_placehold'),'',0),
(1,current_timestamp(),current_timestamp(),'','','','','','','','','','',current_timestamp(),current_timestamp(),'',0,'',0,('shop_order_placehold'),'',0),
(1,current_timestamp(),current_timestamp(),'','','','','','','','','','',current_timestamp(),current_timestamp(),'',0,'',0,('shop_order_placehold'),'',0),
(1,current_timestamp(),current_timestamp(),'','','','','','','','','','',current_timestamp(),current_timestamp(),'',0,'',0,('shop_order_placehold'),'',0);

INSERT INTO wp_wc_orders (id,date_created_gmt,date_updated_gmt)
SELECT ID,current_timestamp()+10,current_timestamp()+10 from wp_posts 
ORDER BY id DESC LIMIT 4;

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you created a changelog file by running pnpm nx affected --target=changelog?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@Konamiman Konamiman self-assigned this Apr 20, 2022
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Apr 20, 2022
@Konamiman Konamiman force-pushed the remove-post_id-from-orders-table branch from 8ec8e7d to 5350907 Compare April 20, 2022 15:02
Note: column is just removed from the schema. No migration is added
to remove the column on existing instances, since the feature is
still in early stages of development.
This post type will be used for placeholder entries for orders
that are created in the orders table when orders->posts sync is off
(placeholder entries are created to reserve a proper order id)
Change the queries from relying on the now removed orders.post_id
column to relying on the existence of placeholder records
in the posts table.
@Konamiman Konamiman force-pushed the remove-post_id-from-orders-table branch from 5350907 to 87172da Compare April 21, 2022 07:43
These tests fail because the code that migrates orders is still
not adapted to the removal of the post_id column in the orders table.
@Konamiman Konamiman marked this pull request as ready for review April 21, 2022 10:05
@Konamiman Konamiman requested a review from vedanshujain April 21, 2022 10:05
Copy link
Contributor

@vedanshujain vedanshujain left a comment

Choose a reason for hiding this comment

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

LGTM!

@vedanshujain vedanshujain merged commit 773d1e5 into trunk Apr 21, 2022
@vedanshujain vedanshujain deleted the remove-post_id-from-orders-table branch April 21, 2022 10:59
@github-actions github-actions bot added this to the 6.6.0 milestone Apr 21, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 21, 2022

Hi @vedanshujain, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:

  • Add the release: add testing instructions label

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

3 participants