prefix). */ const TABLE_BASE = 'prv_call_io'; /** * Create or upgrade the call-io table via dbDelta. * * Safe to call on every plugins_loaded — dbDelta is idempotent. * Side effects: Database write. * * @return void */ public static function create_table(): void { global $wpdb; $table = $wpdb->prefix . self::TABLE_BASE; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE {$table} ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, call_id BIGINT(20) UNSIGNED NOT NULL, prompt_text LONGTEXT NOT NULL DEFAULT '', response_text LONGTEXT NOT NULL DEFAULT '', captured_at DATETIME NOT NULL, PRIMARY KEY (id), KEY call_id (call_id), KEY captured_at (captured_at) ) {$charset_collate};"; if ( ! function_exists( 'dbDelta' ) ) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; } dbDelta( $sql ); } /** * Get the full table name including WP prefix. * * @return string */ public static function get_table_name(): string { global $wpdb; return $wpdb->prefix . self::TABLE_BASE; } /** * Drop the table. Called from uninstall.php only. * * Side effects: Permanently destroys all I/O records. * * @return void */ public static function drop_table(): void { global $wpdb; $table = $wpdb->prefix . self::TABLE_BASE; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->query( "DROP TABLE IF EXISTS {$table}" ); } }