get_charset_collate(); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( "CREATE TABLE {$wpdb->prefix}statbird_customers ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, customer_key char(32) NOT NULL, user_id bigint(20) unsigned NOT NULL DEFAULT 0, email varchar(190) NOT NULL DEFAULT '', name varchar(190) NOT NULL DEFAULT '', first_order datetime NULL, last_order datetime NULL, orders int(10) unsigned NOT NULL DEFAULT 0, spent decimal(19,4) NOT NULL DEFAULT 0, avg_gap_days decimal(9,2) NULL, r tinyint(1) unsigned NOT NULL DEFAULT 0, f tinyint(1) unsigned NOT NULL DEFAULT 0, m tinyint(1) unsigned NOT NULL DEFAULT 0, segment varchar(32) NOT NULL DEFAULT '', churn_risk tinyint(3) unsigned NOT NULL DEFAULT 0, value_12m decimal(19,4) NOT NULL DEFAULT 0, updated_at datetime NOT NULL, run_id int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE KEY customer_key (customer_key), KEY user_id (user_id), KEY segment (segment), KEY last_order (last_order) ) $c;" ); dbDelta( "CREATE TABLE {$wpdb->prefix}statbird_changes ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, customer_key char(32) NOT NULL, from_segment varchar(32) NOT NULL DEFAULT '', to_segment varchar(32) NOT NULL, changed_at datetime NOT NULL, PRIMARY KEY (id), KEY customer_key (customer_key), KEY changed_at (changed_at) ) $c;" ); } }