# Correction du pré-remplissage du PCI Slot ## Problème identifié Lors de l'import de périphériques PCI, le slot (ex: `08:00.0`) n'était pas pré-rempli dans le formulaire. ### Diagnostic Le code tentait de pré-remplir un champ `device_id` qui n'existe pas dans le modèle: **Backend** (`peripherals.py` ligne 1507): ```python "device_id": device_info.get("slot"), # ❌ Ce champ n'existe pas ``` **Frontend** (`peripherals.js` lignes 1839-1842): ```javascript if (suggested.device_id) { const deviceIdField = document.getElementById('device_id'); // ❌ Ce champ n'existe pas if (deviceIdField) deviceIdField.value = suggested.device_id; } ``` ### Analyse du modèle Le modèle `Peripheral` possédait: - `device_id` (INTEGER) - Lien vers la table devices (assignation actuelle) - `linked_device_id` (INTEGER) - Lien vers data.db pour benchmarks - `usb_device_id` (TEXT) - Format `idVendor:idProduct` (ex: `1d6b:0003`) - `pci_device_id` (VARCHAR) - Format `vendor:device` (ex: `10de:2504`) **Mais pas de champ pour stocker le slot PCI** (`08:00.0`). ## Solution implémentée ### 1. Nouveau champ `pci_slot` Ajout d'un champ dédié pour stocker le slot PCI (Bus:Device.Function). #### Migration 014 **Fichier**: `migrations/014_add_pci_slot.sql` ```sql ALTER TABLE peripherals ADD COLUMN pci_slot VARCHAR(20); CREATE INDEX idx_peripherals_pci_slot ON peripherals(pci_slot); ``` **Application**: ```bash python3 backend/apply_migration_014.py ``` **Résultat**: ``` ✅ Migration 014 applied successfully ✅ Column 'pci_slot' added: (68, 'pci_slot', 'VARCHAR(20)', 0, None, 0) ``` ### 2. Modèle mis à jour **Fichier**: `backend/app/models/peripheral.py` (ligne 72) ```python usb_device_id = Column(String(20)) # idVendor:idProduct (e.g. 1d6b:0003) pci_device_id = Column(String(20)) # vendor:device for PCI (e.g. 10ec:8168) pci_slot = Column(String(20)) # PCI slot identifier (e.g. 08:00.0) ← NOUVEAU ``` ### 3. Schéma mis à jour **Fichier**: `backend/app/schemas/peripheral.py` (ligne 63) ```python usb_device_id: Optional[str] = Field(None, max_length=20) pci_device_id: Optional[str] = Field(None, max_length=20) pci_slot: Optional[str] = Field(None, max_length=20) # ← NOUVEAU ``` ### 4. Backend corrigé **Fichier**: `backend/app/api/endpoints/peripherals.py` (ligne 1507) ```python suggested = { "nom": nom, "type_principal": type_principal, "sous_type": sous_type, "marque": brand or device_info.get("vendor_name"), "modele": model or device_info.get("device_name"), "pci_slot": device_info.get("slot"), # ✅ Utilise pci_slot "pci_device_id": device_info.get("pci_device_id"), "cli_raw": device_section, "caracteristiques_specifiques": caracteristiques_specifiques } ``` ### 5. Frontend corrigé **Fichier**: `frontend/js/peripherals.js` (lignes 1838-1842) ```javascript // Fill PCI slot (like 08:00.0) if (suggested.pci_slot) { const pciSlotField = document.getElementById('pci_slot'); if (pciSlotField) pciSlotField.value = suggested.pci_slot; } ``` ### 6. Formulaire HTML mis à jour **Fichier**: `frontend/peripherals.html` (lignes 183-196) ```html