diff --git a/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.py b/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.py index 1a791ea54ef..69ab50f6c90 100755 --- a/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.py +++ b/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.py @@ -194,19 +194,13 @@ def deletePilots(self, pilotIDs, conn=False): if not isinstance(pilotIDs, list): return S_ERROR("Input argument is not a List") - failed = [] - result = self._escapeValues(pilotIDs) if not result["OK"]: return S_ERROR(f"Failed to remove pilot: {result['Value']}") stringIDs = ",".join(result["Value"]) - for table in ["PilotOutput", "JobToPilotMapping", "PilotAgents"]: - result = self._update(f"DELETE FROM {table} WHERE PilotID in ({stringIDs})", conn=conn) - if not result["OK"]: - failed.append(table) - - if failed: - return S_ERROR(f"Failed to remove pilot from {', '.join(failed)} tables") + result = self._update(f"DELETE FROM PilotAgents WHERE PilotID in ({stringIDs})", conn=conn) + if not result["OK"]: + return S_ERROR("Failed to remove pilots: ", result["Message"]) return S_OK(pilotIDs) ########################################################################################## diff --git a/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.sql b/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.sql index 24cbe5a82b8..8b6f8eb6a10 100755 --- a/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.sql +++ b/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.sql @@ -55,8 +55,8 @@ CREATE TABLE `JobToPilotMapping` ( `PilotID` INT(11) UNSIGNED NOT NULL, `JobID` INT(11) UNSIGNED NOT NULL, `StartTime` DATETIME NOT NULL, - KEY `JobID` (`JobID`), - KEY `PilotID` (`PilotID`) + PRIMARY KEY (`PilotID`, `JobID`), + FOREIGN KEY (`PilotID`) REFERENCES `PilotAgents`(`PilotID`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; DROP TABLE IF EXISTS `PilotOutput`; @@ -64,5 +64,6 @@ CREATE TABLE `PilotOutput` ( `PilotID` INT(11) UNSIGNED NOT NULL, `StdOutput` MEDIUMTEXT, `StdError` MEDIUMTEXT, - PRIMARY KEY (`PilotID`) + PRIMARY KEY (`PilotID`), + FOREIGN KEY (`PilotID`) REFERENCES `PilotAgents`(`PilotID`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;