Automattic\WooCommerce\Internal\DataStores\StockNotifications

StockNotificationsDataStore::get_database_schemapublicWC 1.0

Get the database schema.

Method of the class: StockNotificationsDataStore{}

No Hooks.

Returns

String.

Usage

$StockNotificationsDataStore = new StockNotificationsDataStore();
$StockNotificationsDataStore->get_database_schema(): string;

StockNotificationsDataStore::get_database_schema() code WC 10.3.6

public function get_database_schema(): string {

	if ( ! Constants::is_true( 'WOOCOMMERCE_BIS_ALPHA_ENABLED' ) ) {
		return '';
	}

	global $wpdb;

	$collate = $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : '';

	$table_name       = $this->get_table_name();
	$meta_table_name  = $this->get_meta_table_name();
	$max_index_length = $this->database_util->get_max_index_length();

	$sql = "
CREATE TABLE $table_name (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
product_id bigint(20) unsigned NOT NULL,
user_id bigint(20) unsigned NOT NULL,
user_email varchar(100) NOT NULL,
status varchar(20) NOT NULL DEFAULT 'pending',
date_created_gmt datetime NULL,
date_modified_gmt datetime NULL,
date_confirmed_gmt datetime NULL,
date_last_attempt_gmt datetime NULL,
date_notified_gmt datetime NULL,
date_cancelled_gmt datetime NULL,
cancellation_source varchar(30) NULL,
PRIMARY KEY  (id),
KEY product_status_attempt (product_id, status, date_last_attempt_gmt, id),
KEY user_lookup (user_id, product_id, status),
KEY email_lookup (user_email, product_id, status)
) $collate;
CREATE TABLE $meta_table_name (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
notification_id bigint(20) unsigned NOT NULL,
meta_key varchar(255) NULL,
meta_value longtext NULL,
PRIMARY KEY  (id),
KEY notification_id (notification_id),
KEY meta_key (meta_key($max_index_length))
) $collate;
	";

	return $sql;
}