Run child tables cascade from run.id

Migration ccb21eacf5d5 deletes rows whose run is gone, then adds foreign keys
with ON DELETE CASCADE from run_node, run_metric and run_artifact to run.id.
Deleting runs is now the one statement. A node or metric written after its
run was deleted is dropped with an info line. Migrations run with foreign keys
off, since a batch rebuild of run would otherwise cascade into every child row.
This commit is contained in:
2026-10-15 10:32:33 +02:00
parent 44223ab168
commit 599e01b0bf
6 changed files with 104 additions and 25 deletions
+7
View File
@@ -585,6 +585,9 @@ class MetricSink:
)
)
session.commit()
except IntegrityError:
# Deleted while it was still reporting, as `_record_node` explains.
logger.info("Run %s is gone; not writing its metrics", self.run_id)
except Exception:
logger.exception(
"Could not write %d metric(s) of %s", len(rows), self.run_id
@@ -1568,6 +1571,10 @@ class RunService:
)
)
session.commit()
except IntegrityError:
# The run was deleted while this node was still going, say once it
# had been swept as abandoned. Its rows have no run to belong to.
logger.info("Run %s is gone; not recording node '%s'", run_id, outcome.node)
except Exception:
logger.exception(
"Could not record node '%s' of run %s", outcome.node, run_id