Fix foreign key error when adding runs

This commit is contained in:
Joscha 2024-05-13 17:26:32 +02:00
parent 437be12f14
commit 5d28a2f04a
3 changed files with 24 additions and 1 deletions

View file

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "\n INSERT OR REPLACE INTO metrics (name, unit)\n VALUES (?, ?)\n ",
"describe": {
"columns": [],
"parameters": {
"Right": 2
},
"nullable": []
},
"hash": "a9cafe3a6ef8bcba95b1b29d5b9bde81f8233804e771b6347a5d165663a39680"
}

View file

@ -38,7 +38,7 @@ CREATE TABLE refs (
CREATE TABLE metrics ( CREATE TABLE metrics (
name TEXT NOT NULL PRIMARY KEY, name TEXT NOT NULL PRIMARY KEY,
unit TEXT, unit TEXT,
direction INT direction INT NOT NULL DEFAULT 0
) STRICT; ) STRICT;
CREATE TABLE runs ( CREATE TABLE runs (

View file

@ -78,6 +78,17 @@ async fn save_work(
.await?; .await?;
for (metric, measurement) in run.measurements { for (metric, measurement) in run.measurements {
sqlx::query!(
"
INSERT OR REPLACE INTO metrics (name, unit)
VALUES (?, ?)
",
metric,
measurement.unit,
)
.execute(&mut *conn)
.await?;
sqlx::query!( sqlx::query!(
" "
INSERT INTO run_measurements ( INSERT INTO run_measurements (