On PR #21245, I added a db update routine to change wp_woocommerce_sessions primary key from session_key char(32) to session_id bigint auto_increment as dbDelta() is unable to handle primary key changes (see https://core.trac.wordpress.org/ticket/40357). But I didn't realize that dbDelta() was actually trying to add a new primary key to the table without droping the old key first and this was generating the following error:
```
WordPress database error Multiple primary key defined for query ALTER TABLE wp_woocommerce_sessions ADD PRIMARY KEY (`session_id`)
```
To prevent this error from happening, this commit moves the query that changes the primary key from db update routine to WC_Install::create_tables() so that it runs before dbDelta() is called.
This commit changes wp_woocommerce_sessions primary key to the bigint field session_id. Before it was the char(32) field session_key. Doing this change primarily as it should reduce the occurrence of deadlocks, but also because it is not a good practice to use a char(32) field as the primary key of a table.
This PR introduces a check on the permission_id FK to ensure that it is not added multiple times on upgrades. It also names the key specifically to ensure future changes to the key can be targeted properly and removes old keys that were added since 3.4.0.
* Add FK check before adding the FK. Also give the FK a name to avoid auto generated names and duplicate keys.
* Remove additional OR
* Remove additional OR
* Final FK check query
* Add foreign key cleanup routine to 3.4.3 db version
* Only check on named foreign key now that we have a cleanup routine in place, use specific phpcignore
* Rework formatting of SQL query
* Change way to fetch and add FK, can't use procedural SQL, needs to be done via statements.
* Add table name to lookup
* Only clean up FK on the wc_download_log table
* Remove erenouse bracket
Turns out WP_Background_Process uses an arbitrary value of 20 seconds of wall clock time to measure PHP "time limit" (b0617a13c4/includes/libraries/wp-background-process.php (L385)) instead of cpu time which apparently it is not easy to measure in PHP. Since system calls (like database calls) are not included in the PHP maximum execution time, 20 seconds of wall clock is often way less than PHP time limit.
Thus, this commit removes the call to WP_Background_Process::time_exceeded() while running the function to migrate the post meta _customer_user to the field post_author. If the script times out, WP_Background_Process will restart it.