Skip to content

Commit 32db990

Browse files
committed
feat: added foreign keys
1 parent c379267 commit 32db990

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,13 @@ def deletePilots(self, pilotIDs, conn=False):
194194
if not isinstance(pilotIDs, list):
195195
return S_ERROR("Input argument is not a List")
196196

197-
failed = []
198-
199197
result = self._escapeValues(pilotIDs)
200198
if not result["OK"]:
201199
return S_ERROR(f"Failed to remove pilot: {result['Value']}")
202200
stringIDs = ",".join(result["Value"])
203-
for table in ["PilotOutput", "JobToPilotMapping", "PilotAgents"]:
204-
result = self._update(f"DELETE FROM {table} WHERE PilotID in ({stringIDs})", conn=conn)
205-
if not result["OK"]:
206-
failed.append(table)
207-
208-
if failed:
209-
return S_ERROR(f"Failed to remove pilot from {', '.join(failed)} tables")
201+
result = self._update(f"DELETE FROM PilotAgents WHERE PilotID in ({stringIDs})", conn=conn)
202+
if not result["OK"]:
203+
return S_ERROR("Failed to remove pilots: ", result["Message"])
210204
return S_OK(pilotIDs)
211205

212206
##########################################################################################

src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ CREATE TABLE `JobToPilotMapping` (
5555
`PilotID` INT(11) UNSIGNED NOT NULL,
5656
`JobID` INT(11) UNSIGNED NOT NULL,
5757
`StartTime` DATETIME NOT NULL,
58-
KEY `JobID` (`JobID`),
59-
KEY `PilotID` (`PilotID`)
58+
PRIMARY KEY (`PilotID`, `JobID`),
59+
FOREIGN KEY (`PilotID`) REFERENCES `PilotAgents`(`PilotID`) ON DELETE CASCADE
6060
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
6161

6262
DROP TABLE IF EXISTS `PilotOutput`;
6363
CREATE TABLE `PilotOutput` (
6464
`PilotID` INT(11) UNSIGNED NOT NULL,
6565
`StdOutput` MEDIUMTEXT,
6666
`StdError` MEDIUMTEXT,
67-
PRIMARY KEY (`PilotID`)
67+
PRIMARY KEY (`PilotID`),
68+
FOREIGN KEY (`PilotID`) REFERENCES `PilotAgents`(`PilotID`) ON DELETE CASCADE
6869
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

src/DIRAC/WorkloadManagementSystem/DB/SandboxMetadataDB.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
""" SandboxMetadataDB class is a front-end to the metadata for sandboxes
2-
"""
1+
"""SandboxMetadataDB class is a front-end to the metadata for sandboxes"""
2+
33
from DIRAC import S_ERROR, S_OK
44
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
55
from DIRAC.Core.Base.DB import DB
@@ -61,10 +61,11 @@ def __initializeDB(self):
6161
"Fields": {
6262
"SBId": "INTEGER(10) UNSIGNED NOT NULL",
6363
"EntityId": "VARCHAR(128) NOT NULL",
64-
"Type": "VARCHAR(64) NOT NULL",
64+
"Type": "ENUM('Input', 'Output') NOT NULL",
6565
},
6666
"Indexes": {"Entity": ["EntityId"], "SBIndex": ["SBId"]},
6767
"PrimaryKey": ["SBId", "EntityId", "Type"],
68+
"ForeignKeys": {"SBId": "sb_SandBoxes.SBId"},
6869
}
6970

7071
for tableName in self.__tablesDesc:

0 commit comments

Comments
 (0)