Skip to content

Commit 1895ff1

Browse files
committed
feat: moved to ON DELETE CASCADE for foreign keys
1 parent 808e29e commit 1895ff1

2 files changed

Lines changed: 2 additions & 17 deletions

File tree

src/DIRAC/Core/Utilities/MySQL.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ def _createTables(self, tableDict, force=False):
10421042
# cmdList.append( '`%s` %s' % ( forTable, tableDict[forTable]['Fields'][forKey] )
10431043
cmdList.append(
10441044
"FOREIGN KEY ( `%s` ) REFERENCES `%s` ( `%s` )"
1045-
" ON DELETE RESTRICT" % (key, forTable, forKey)
1045+
" ON DELETE CASCADE" % (key, forTable, forKey)
10461046
)
10471047

10481048
engine = thisTable.get("Engine", "InnoDB")

src/DIRAC/WorkloadManagementSystem/DB/TaskQueueDB.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,7 @@ def cleanOrphanedTaskQueues(self, connObj=False):
319319
if not orphanedTQs:
320320
return S_OK()
321321
orphanedTQs = [str(otq[0]) for otq in orphanedTQs]
322-
323-
for mvField in multiValueDefFields:
324-
result = self._update(
325-
f"DELETE FROM `tq_TQTo{mvField}` WHERE TQId in ( {','.join(orphanedTQs)} )", conn=connObj
326-
)
327-
if not result["OK"]:
328-
return result
329-
330-
result = self._update(f"DELETE FROM `tq_TaskQueues` WHERE TQId in ( {','.join(orphanedTQs)} )", conn=connObj)
331-
if not result["OK"]:
332-
return result
333-
return S_OK()
322+
return self._update(f"DELETE FROM `tq_TaskQueues` WHERE TQId in ( {','.join(orphanedTQs)} )", conn=connObj)
334323

335324
def __setTaskQueueEnabled(self, tqId, enabled=True, connObj=False):
336325
if enabled:
@@ -990,10 +979,6 @@ def deleteTaskQueueIfEmpty(self, tqId, tqOwner=False, tqOwnerGroup=False, connOb
990979
tqToDel = retVal["Value"]
991980

992981
if tqToDel:
993-
for mvField in multiValueDefFields:
994-
retVal = self._update(f"DELETE FROM `tq_TQTo{mvField}` WHERE TQId = {tqId}", conn=connObj)
995-
if not retVal["OK"]:
996-
return retVal
997982
retVal = self._update(f"DELETE FROM `tq_TaskQueues` WHERE TQId = {tqId}", conn=connObj)
998983
if not retVal["OK"]:
999984
return retVal

0 commit comments

Comments
 (0)