WC_Install::get_schema PHP Method

get_schema() private static method

https://github.com/woocommerce/woocommerce/wiki/Database-Description/
private static get_schema ( ) : string
return string
    private static function get_schema()
    {
        global $wpdb;
        $collate = '';
        if ($wpdb->has_cap('collation')) {
            $collate = $wpdb->get_charset_collate();
        }
        /*
         * Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
         * As of WordPress 4.2, however, we moved to utf8mb4, which uses 4 bytes per character. This means that an index which
         * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
         *
         * This may cause duplicate index notices in logs due to https://core.trac.wordpress.org/ticket/34870 but dropping
         * indexes first causes too much load on some servers/larger DB.
         */
        $max_index_length = 191;
        $tables = "\nCREATE TABLE {$wpdb->prefix}woocommerce_sessions (\n  session_id bigint(20) NOT NULL AUTO_INCREMENT,\n  session_key char(32) NOT NULL,\n  session_value longtext NOT NULL,\n  session_expiry bigint(20) NOT NULL,\n  PRIMARY KEY  (session_key),\n  UNIQUE KEY session_id (session_id)\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_api_keys (\n  key_id bigint(20) NOT NULL auto_increment,\n  user_id bigint(20) NOT NULL,\n  description longtext NULL,\n  permissions varchar(10) NOT NULL,\n  consumer_key char(64) NOT NULL,\n  consumer_secret char(43) NOT NULL,\n  nonces longtext NULL,\n  truncated_key char(7) NOT NULL,\n  last_access datetime NULL default null,\n  PRIMARY KEY  (key_id),\n  KEY consumer_key (consumer_key),\n  KEY consumer_secret (consumer_secret)\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_attribute_taxonomies (\n  attribute_id bigint(20) NOT NULL auto_increment,\n  attribute_name varchar(200) NOT NULL,\n  attribute_label longtext NULL,\n  attribute_type varchar(200) NOT NULL,\n  attribute_orderby varchar(200) NOT NULL,\n  attribute_public int(1) NOT NULL DEFAULT 1,\n  PRIMARY KEY  (attribute_id),\n  KEY attribute_name (attribute_name({$max_index_length}))\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_downloadable_product_permissions (\n  permission_id bigint(20) NOT NULL auto_increment,\n  download_id varchar(32) NOT NULL,\n  product_id bigint(20) NOT NULL,\n  order_id bigint(20) NOT NULL DEFAULT 0,\n  order_key varchar(200) NOT NULL,\n  user_email varchar(200) NOT NULL,\n  user_id bigint(20) NULL,\n  downloads_remaining varchar(9) NULL,\n  access_granted datetime NOT NULL default '0000-00-00 00:00:00',\n  access_expires datetime NULL default null,\n  download_count bigint(20) NOT NULL DEFAULT 0,\n  PRIMARY KEY  (permission_id),\n  KEY download_order_key_product (product_id,order_id,order_key({$max_index_length}),download_id),\n  KEY download_order_product (download_id,order_id,product_id)\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_order_items (\n  order_item_id bigint(20) NOT NULL auto_increment,\n  order_item_name longtext NOT NULL,\n  order_item_type varchar(200) NOT NULL DEFAULT '',\n  order_id bigint(20) NOT NULL,\n  PRIMARY KEY  (order_item_id),\n  KEY order_id (order_id)\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_order_itemmeta (\n  meta_id bigint(20) NOT NULL auto_increment,\n  order_item_id bigint(20) NOT NULL,\n  meta_key varchar(255) default NULL,\n  meta_value longtext NULL,\n  PRIMARY KEY  (meta_id),\n  KEY order_item_id (order_item_id),\n  KEY meta_key (meta_key({$max_index_length}))\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_tax_rates (\n  tax_rate_id bigint(20) NOT NULL auto_increment,\n  tax_rate_country varchar(200) NOT NULL DEFAULT '',\n  tax_rate_state varchar(200) NOT NULL DEFAULT '',\n  tax_rate varchar(200) NOT NULL DEFAULT '',\n  tax_rate_name varchar(200) NOT NULL DEFAULT '',\n  tax_rate_priority bigint(20) NOT NULL,\n  tax_rate_compound int(1) NOT NULL DEFAULT 0,\n  tax_rate_shipping int(1) NOT NULL DEFAULT 1,\n  tax_rate_order bigint(20) NOT NULL,\n  tax_rate_class varchar(200) NOT NULL DEFAULT '',\n  PRIMARY KEY  (tax_rate_id),\n  KEY tax_rate_country (tax_rate_country({$max_index_length})),\n  KEY tax_rate_state (tax_rate_state({$max_index_length})),\n  KEY tax_rate_class (tax_rate_class({$max_index_length})),\n  KEY tax_rate_priority (tax_rate_priority)\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations (\n  location_id bigint(20) NOT NULL auto_increment,\n  location_code varchar(255) NOT NULL,\n  tax_rate_id bigint(20) NOT NULL,\n  location_type varchar(40) NOT NULL,\n  PRIMARY KEY  (location_id),\n  KEY tax_rate_id (tax_rate_id),\n  KEY location_type (location_type),\n  KEY location_type_code (location_type(40),location_code(90))\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_shipping_zones (\n  zone_id bigint(20) NOT NULL auto_increment,\n  zone_name varchar(255) NOT NULL,\n  zone_order bigint(20) NOT NULL,\n  PRIMARY KEY  (zone_id)\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_shipping_zone_locations (\n  location_id bigint(20) NOT NULL auto_increment,\n  zone_id bigint(20) NOT NULL,\n  location_code varchar(255) NOT NULL,\n  location_type varchar(40) NOT NULL,\n  PRIMARY KEY  (location_id),\n  KEY location_id (location_id),\n  KEY location_type (location_type),\n  KEY location_type_code (location_type(40),location_code(90))\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_shipping_zone_methods (\n  zone_id bigint(20) NOT NULL,\n  instance_id bigint(20) NOT NULL auto_increment,\n  method_id varchar(255) NOT NULL,\n  method_order bigint(20) NOT NULL,\n  is_enabled tinyint(1) NOT NULL DEFAULT '1',\n  PRIMARY KEY  (instance_id)\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_payment_tokens (\n  token_id bigint(20) NOT NULL auto_increment,\n  gateway_id varchar(255) NOT NULL,\n  token text NOT NULL,\n  user_id bigint(20) NOT NULL DEFAULT '0',\n  type varchar(255) NOT NULL,\n  is_default tinyint(1) NOT NULL DEFAULT '0',\n  PRIMARY KEY  (token_id),\n  KEY user_id (user_id)\n) {$collate};\nCREATE TABLE {$wpdb->prefix}woocommerce_payment_tokenmeta (\n  meta_id bigint(20) NOT NULL auto_increment,\n  payment_token_id bigint(20) NOT NULL,\n  meta_key varchar(255) NULL,\n  meta_value longtext NULL,\n  PRIMARY KEY  (meta_id),\n  KEY payment_token_id (payment_token_id),\n  KEY meta_key (meta_key({$max_index_length}))\n) {$collate};\n\t\t";
        // Term meta is only needed for old installs.
        if (!function_exists('get_term_meta')) {
            $tables .= "\nCREATE TABLE {$wpdb->prefix}woocommerce_termmeta (\n  meta_id bigint(20) NOT NULL auto_increment,\n  woocommerce_term_id bigint(20) NOT NULL,\n  meta_key varchar(255) default NULL,\n  meta_value longtext NULL,\n  PRIMARY KEY  (meta_id),\n  KEY woocommerce_term_id (woocommerce_term_id),\n  KEY meta_key (meta_key({$max_index_length}))\n) {$collate};\n\t\t\t";
        }
        return $tables;
    }