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
+9 -3
View File
@@ -432,7 +432,9 @@ class RunNode(SQLModel, table=True):
__tablename__ = "run_node"
run_id: str = Field(primary_key=True, max_length=64)
run_id: str = Field(
primary_key=True, max_length=64, foreign_key="run.id", ondelete="CASCADE"
)
node: str = Field(primary_key=True, max_length=255)
#: ok, error, skipped, cached or cancelled.
status: str = Field(default="ok", max_length=16)
@@ -470,7 +472,9 @@ class RunMetric(SQLModel, table=True):
__tablename__ = "run_metric"
run_id: str = Field(primary_key=True, max_length=64)
run_id: str = Field(
primary_key=True, max_length=64, foreign_key="run.id", ondelete="CASCADE"
)
name: str = Field(primary_key=True, max_length=128)
#: -1 for a value with no step of its own — a final score.
step: int = Field(primary_key=True)
@@ -484,7 +488,9 @@ class RunArtifact(SQLModel, table=True):
__tablename__ = "run_artifact"
run_id: str = Field(primary_key=True, max_length=64)
run_id: str = Field(
primary_key=True, max_length=64, foreign_key="run.id", ondelete="CASCADE"
)
#: The message the bytes left the node on, which is what addresses them.
name: str = Field(primary_key=True, max_length=255)
#: What the node called the file, when it said. Kept because a reference