prefix . 'bloatwright_' . $name; } /** * All tables. * * @return string[] */ public static function tables(): array { return array( self::table( 'sessions' ), self::table( 'requests' ) ); } /** * Create/upgrade. */ public static function install(): void { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $charset = $wpdb->get_charset_collate(); $sessions = self::table( 'sessions' ); $requests = self::table( 'requests' ); dbDelta( "CREATE TABLE {$sessions} ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, started_at DATETIME NOT NULL, finished_at DATETIME NULL, mode VARCHAR(10) NOT NULL DEFAULT 'auto', passes TINYINT UNSIGNED NOT NULL DEFAULT 3, urls TEXT NOT NULL, exclude_slug VARCHAR(191) NULL, baseline_id BIGINT UNSIGNED NULL, status VARCHAR(10) NOT NULL DEFAULT 'running', progress TEXT NULL, summary LONGTEXT NULL, label VARCHAR(191) NULL, PRIMARY KEY (id), KEY status (status) ) {$charset};" ); dbDelta( "CREATE TABLE {$requests} ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, session_id BIGINT UNSIGNED NOT NULL, url VARCHAR(2048) NOT NULL, pass TINYINT UNSIGNED NOT NULL DEFAULT 1, total_ms DECIMAL(9,2) NOT NULL DEFAULT 0, peak_mem_kb INT UNSIGNED NOT NULL DEFAULT 0, query_count SMALLINT UNSIGNED NOT NULL DEFAULT 0, data LONGTEXT NOT NULL, created_at DATETIME NOT NULL, PRIMARY KEY (id), KEY session (session_id) ) {$charset};" ); update_option( self::OPTION, self::VERSION, true ); // Read on every request at plugins_loaded: autoload it. } /** * Upgrade when the version changed. */ public static function maybe_upgrade(): void { if ( get_option( self::OPTION ) !== self::VERSION ) { self::install(); } } }