| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Database; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
class CreateOrderTable { |
| 10 |
|
| 11 |
public static function up( $prefix, $charset_collate ) { |
| 12 |
/** |
| 13 |
* Filters the maximum index length in the database. |
| 14 |
* |
| 15 |
* Indexes have a maximum size of 767 bytes. Historically, we haven't needed to be concerned about that. |
| 16 |
* As of WP 4.2, however, they moved to utf8mb4, which uses 4 bytes per character. This means that an index which |
| 17 |
* used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters. |
| 18 |
* |
| 19 |
* Additionally, MyISAM engine also limits the index size to 1000 bytes. We add this filter so that interested folks on InnoDB engine can increase the size till allowed 3071 bytes. |
| 20 |
* Index length cannot be more than 768, which is 3078 bytes in utf8mb4 and max allowed by InnoDB engine. |
| 21 |
*/ |
| 22 |
$max_index_length = 191; |
| 23 |
$composite_customer_id_email_length = 171; // (191 - 20) 8 for customer_id, 20 minimum for email. |
| 24 |
|
| 25 |
$table_name = $prefix . 'storeengine_orders'; |
| 26 |
$sql = "CREATE TABLE IF NOT EXISTS {$table_name} ( |
| 27 |
id bigint(20) unsigned NOT NULL auto_increment, |
| 28 |
status varchar(20), |
| 29 |
currency varchar(10), |
| 30 |
type varchar(20), |
| 31 |
tax_amount decimal(26,8), |
| 32 |
total_amount decimal(26,8), |
| 33 |
customer_id bigint(20) unsigned, |
| 34 |
billing_email varchar(320), |
| 35 |
date_created_gmt datetime, |
| 36 |
date_updated_gmt datetime, |
| 37 |
parent_order_id bigint(20) unsigned, |
| 38 |
payment_method varchar(100), |
| 39 |
payment_method_title text, |
| 40 |
transaction_id varchar(100), |
| 41 |
ip_address varchar(100), |
| 42 |
user_agent text, |
| 43 |
customer_note text, |
| 44 |
hash varchar(255), |
| 45 |
PRIMARY KEY (id), |
| 46 |
INDEX status (status), |
| 47 |
INDEX date_created (date_created_gmt), |
| 48 |
INDEX customer_id_billing_email (customer_id, billing_email($composite_customer_id_email_length)), |
| 49 |
INDEX billing_email (billing_email($max_index_length)), |
| 50 |
INDEX type_status_date (type,status,date_created_gmt), |
| 51 |
INDEX parent_order_id (parent_order_id), |
| 52 |
INDEX date_updated (date_updated_gmt) |
| 53 |
) $charset_collate;"; |
| 54 |
|
| 55 |
dbDelta( $sql ); |
| 56 |
} |
| 57 |
} |
| 58 |
|