As we are progressing with implementing the custom order table project, we would like to open up a call for testing to test our migration processes.
Please note that this is only the first milestone from a much larger effort, but we would still appreciate some early feedback. The main goal of this call for testing is to test the migration process across various hosts and server combinations. More specifically, we’re interested in:
- Finding out and resolving any major issues/bugs in our migration routines.
- Finding out how much time and server resources migrations will take.
This call for testing is intended for developers, agencies, and hosting partners only as it will need you to set up a staging environment and database and run custom code.
Please use a staging database for testing, don’t try out the testing steps on your production database.
Migration Details
To recap, we intend to migrate orders from wp_posts
and wp_postmeta
table to four custom order tables that we added to our design scheme:
- wp_wc_orders
- wp_wc_order_addresses
- wp_wc_order_operational_data
- wp_wc_orders_meta
You can read in detail about the structure of these tables in our initial planning proposal.
Testing guide
Since the project is incomplete, any features and code related to the project don’t load by default. Follow these steps to get the feature enabled for testing:
Testing environment and WP CLI
For this testing, you will need a staging environment and a staging database as it will put a lot of load on your database (and your wp_posts and wp_postmeta tables). Additionally, the testing environment needs to be configured with WP-CLI.
Make sure that there are some orders already in your staging database. You can duplicate the production database into your staging/test database; this way, you will accurately know how much time migrations will take when we enable the feature eventually. You can also use the smooth generator to generate dummy orders.
The steps to testing are as follows:
- Getting the latest WooCommerce build which has the custom order table feature code.
- Enabling the custom order table feature.
- Running migrations via the WP-CLI (and optionally, via Action Scheduler)
- Reporting back the results
Get the latest WooCommerce build.
The code for testing is currently not included in any official release. You can download this build package with the required migration code and upload it to your staging site.
Enable the feature
Enabling the custom order table feature currently requires a lot of manual steps. This is intentional so that merchants may not accidentally enable the feature before it’s complete and stable.
To enable the feature:
- Add this code snippet to your staging site:
function enable_cot(){
$order_controller = wc_get_container()
->get('Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController');
if( isset( $order_controller ) ) {
$order_controller->show_feature();
}
}
add_action( 'init', 'enable_cot', 99 );
2. Go to WooCommerce > Status > Tools and find the tool with the title Create the custom orders tables
. Click on the Create
button
3. You should see a message that custom tables were created like so:
4. Now, the custom order table feature should be enabled. You can verify by going to WooCommerce > Settings > Advanced > Custom Data Stores.
If you have orders yet to be migrated, which will likely be the case, you will see the option to switch to the custom order table disabled with pending orders count like so:
If the shop didn’t have any orders, the UI would look like this:
Make sure that the checkbox Keep the posts table and the orders tables synchronized
is unchecked for now. Ticking this checkbox and saving changes will trigger the migration process in the background, which we don’t want at this time in our testing.
Running migrations
Now that we are all set up, it’s time to test out by running migrations. There are two ways to run the migration, either via CLI, which we recommend for particularly large shops or via Action Scheduler, which is the default way and would be useful for regular merchants.
Running migration via WP CLI
You would need WP-CLI installed and configured in your staging environment for this method. Follow the installation heading on WP-CLI page for information about how to set it up.
We have added commands for migration under the wp wc cot
namespace. Let’s test them out.
Run the command to count the number of orders to be migrated – wp wc cot count_unmigrated
:
> wp wc cot count_unmigrated
There are 22872 orders to be migrated.
>
If you don’t have any orders or all the orders are already migrated, this will be reported as 0.
Next, run the command to actually migrate all orders – wp wc cot migrate
. Note that this command will take a while to complete and will put a load on your database.
> wp wc cot migrate
This feature is not production ready yet. Make sure you are not running these commands in your production environment.
There are 22872 orders to be migrated.
Order Data Migration 100% [===========================================================================================================] 1:34 / 1:12
Migration completed.
Success: 22872 orders were migrated in 90.777226 seconds
Now that all our orders are migrated let’s verify that all data was migrated as it should. To do this, run the verify command – wp wc cot verify_cot_data
> wp wc cot verify_cot_data
This feature is not production ready yet. Make sure you are not running these commands in your production environment.
There are 22872 orders to be verified.
Order Data Verification 100% [========================================================================================================] 5:27 / 4:54
Verification completed.
Success: 22872 orders were verified in 333.464455 seconds
Starting over by dropping tables
If you’d like to run the migration again, you can drop the tables and start the process all over again. To drop custom order tables, go to WooCommerce > Status > Tools and run the Delete the custom orders tables
tool.
After deleting the custom order tables, the tool for creating the table will come back, and you will be able to start the process from scratch.
Running migrations via Action Scheduler
You can also run the migrations from the background by scheduling them via actions. To start that process, go to WooCommerce > Settings > Advanced > Custom Data Stores, enable the checkbox with the label Keep the posts table and the orders tables synchronized
and save changes.
After starting the process, you can check the progress by refreshing the page. We process 250 orders in a single batch in the background migration process by default.
Clicking on Save changes
button will trigger the migration again, which may be useful in case the process is stuck for some reason. Although, it may take a while to update the order count.
Request for feedback
If you are testing, we request that you share the following information in the comments of this post:
- How much time did it take to run the migration? How many orders were migrated? What were the server memory size and DB version (you can get these details from the system status report under the heading
WordPress memory limit
andMySQL version
respectively)? - You can change the batch size if the memory configured on the PHP server is low by providing the
--batch-size
option in the CLI command. Did you need to use this option, or was the default batch size of 500 orders good enough? - What all issues did you face during the migration process?
- Any other details you would like to share or any comments on the process.
Leave a Reply