Group migrations

This commit is contained in:
Joscha 2023-08-15 19:01:28 +02:00
parent 2714280567
commit 82e2385f59
12 changed files with 105 additions and 103 deletions

View file

@ -1,10 +1,10 @@
{
"db_name": "SQLite",
"query": "SELECT name, value, stddev, unit, direction FROM run_measurements WHERE id = ? ORDER BY name ASC ",
"query": "SELECT metric, value, stddev, unit, direction FROM run_measurements WHERE id = ? ORDER BY metric ASC ",
"describe": {
"columns": [
{
"name": "name",
"name": "metric",
"ordinal": 0,
"type_info": "Text"
},
@ -40,5 +40,5 @@
true
]
},
"hash": "b65eb154a77e79de390220d3675cc2b1ebe8cb706d2b0e1a0377c88fd6a175c2"
"hash": "0a4a3c4090e70ca643c4af0368ecf5c8dde66d898a900afa299a94e9a7bc62f8"
}

View file

@ -1,12 +0,0 @@
{
"db_name": "SQLite",
"query": "INSERT INTO run_measurements ( id, name, value, stddev, unit, direction ) VALUES (?, ?, ?, ?, ?, ?) ",
"describe": {
"columns": [],
"parameters": {
"Right": 6
},
"nullable": []
},
"hash": "33cbc60a8d06adf3c3836d4193a80139615b69896a84dd1340759db6adbebf1f"
}

View file

@ -1,6 +1,6 @@
{
"db_name": "SQLite",
"query": "WITH measurements AS ( SELECT hash, value, MAX(start) FROM runs JOIN run_measurements USING (id) WHERE name = ? GROUP BY hash ) SELECT value FROM commits LEFT JOIN measurements USING (hash) WHERE reachable = 2 ORDER BY unixepoch(committer_date) ASC, hash ASC ",
"query": "WITH measurements AS ( SELECT hash, value, MAX(start) FROM runs JOIN run_measurements USING (id) WHERE metric = ? GROUP BY hash ) SELECT value FROM commits LEFT JOIN measurements USING (hash) WHERE reachable = 2 ORDER BY unixepoch(committer_date) ASC, hash ASC ",
"describe": {
"columns": [
{
@ -16,5 +16,5 @@
true
]
},
"hash": "75264d014081dd190d880b89b415cecfd70dec9b56905027e27455c1dd4db02e"
"hash": "50ae538fd51000e8b4988981f66aed60bc30de2bb8cbb4a1533dfd551503b50a"
}

View file

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "INSERT INTO run_measurements ( id, metric, value, stddev, unit, direction ) VALUES (?, ?, ?, ?, ?, ?) ",
"describe": {
"columns": [],
"parameters": {
"Right": 6
},
"nullable": []
},
"hash": "971b811933eb0ab6ae4f23d6179f7035be88c7134b05118c20b106f10d299fe9"
}

View file

@ -1,33 +0,0 @@
CREATE TABLE commits (
hash TEXT NOT NULL PRIMARY KEY,
author TEXT NOT NULL,
author_date TEXT NOT NULL,
committer TEXT NOT NULL,
committer_date TEXT NOT NULL,
message TEXT NOT NULL,
reachable INT NOT NULL DEFAULT 0,
new INT NOT NULL DEFAULT 1
) STRICT;
CREATE TABLE commit_links (
child TEXT NOT NULL,
parent TEXT NOT NULL,
PRIMARY KEY (parent, child),
FOREIGN KEY (parent) REFERENCES commits (hash) ON DELETE CASCADE,
FOREIGN KEY (child) REFERENCES commits (hash) ON DELETE CASCADE
) STRICT;
CREATE TABLE refs (
name TEXT NOT NULL PRIMARY KEY,
hash TEXT NOT NULL,
tracked INT NOT NULL DEFAULT 0,
FOREIGN KEY (hash) REFERENCES commits (hash) ON DELETE CASCADE
) STRICT;
CREATE INDEX idx_commits_committer_date_hash
ON commits (unixepoch(committer_date), hash);
CREATE INDEX idx_commit_links_parent_child
ON commit_links (parent, child);

View file

@ -1,7 +0,0 @@
CREATE TABLE queue (
hash TEXT NOT NULL PRIMARY KEY,
date TEXT NOT NULL,
priority INT NOT NULL DEFAULT 0,
FOREIGN KEY (hash) REFERENCES commits (hash) ON DELETE CASCADE
) STRICT;

View file

@ -1,37 +0,0 @@
CREATE TABLE runs (
id TEXT NOT NULL PRIMARY KEY,
hash TEXT NOT NULL,
bench_method TEXT NOT NULL,
worker_name TEXT NOT NULL,
worker_info TEXT,
start TEXT NOT NULL,
end TEXT NOT NULL,
exit_code INT NOT NULL,
FOREIGN KEY (hash) REFERENCES commits (hash) ON DELETE CASCADE
) STRICT;
CREATE TABLE run_measurements (
id TEXT NOT NULL,
name TEXT NOT NULL,
value REAL NOT NULL,
stddev REAL,
unit TEXT,
direction INT,
PRIMARY KEY (id, name),
FOREIGN KEY (id) REFERENCES runs (id) ON DELETE CASCADE
) STRICT;
CREATE TABLE run_output (
id TEXT NOT NULL,
idx INT NOT NULL,
source INT NOT NULL,
text TEXT NOT NULL,
PRIMARY KEY (id, idx),
FOREIGN KEY (id) REFERENCES runs (id) ON DELETE CASCADE
) STRICT;
CREATE INDEX idx_run_measurements_name_id_value
ON run_measurements (name, id, value);

View file

@ -0,0 +1,76 @@
CREATE TABLE commits (
hash TEXT NOT NULL PRIMARY KEY,
author TEXT NOT NULL,
author_date TEXT NOT NULL,
committer TEXT NOT NULL,
committer_date TEXT NOT NULL,
message TEXT NOT NULL,
reachable INT NOT NULL DEFAULT 0,
new INT NOT NULL DEFAULT 1
) STRICT;
CREATE TABLE commit_links (
child TEXT NOT NULL,
parent TEXT NOT NULL,
PRIMARY KEY (parent, child),
FOREIGN KEY (parent) REFERENCES commits (hash) ON DELETE CASCADE,
FOREIGN KEY (child) REFERENCES commits (hash) ON DELETE CASCADE
) STRICT;
CREATE TABLE refs (
name TEXT NOT NULL PRIMARY KEY,
hash TEXT NOT NULL,
tracked INT NOT NULL DEFAULT 0,
FOREIGN KEY (hash) REFERENCES commits (hash) ON DELETE CASCADE
) STRICT;
CREATE TABLE runs (
id TEXT NOT NULL PRIMARY KEY,
hash TEXT NOT NULL,
bench_method TEXT NOT NULL,
worker_name TEXT NOT NULL,
worker_info TEXT,
start TEXT NOT NULL,
end TEXT NOT NULL,
exit_code INT NOT NULL,
FOREIGN KEY (hash) REFERENCES commits (hash) ON DELETE CASCADE
) STRICT;
CREATE TABLE run_measurements (
id TEXT NOT NULL,
metric TEXT NOT NULL,
value REAL NOT NULL,
stddev REAL,
unit TEXT,
direction INT,
PRIMARY KEY (id, metric),
FOREIGN KEY (id) REFERENCES runs (id) ON DELETE CASCADE
) STRICT;
CREATE TABLE run_output (
id TEXT NOT NULL,
idx INT NOT NULL,
source INT NOT NULL,
text TEXT NOT NULL,
PRIMARY KEY (id, idx),
FOREIGN KEY (id) REFERENCES runs (id) ON DELETE CASCADE
) STRICT;
CREATE TABLE queue (
hash TEXT NOT NULL PRIMARY KEY,
date TEXT NOT NULL,
priority INT NOT NULL DEFAULT 0,
FOREIGN KEY (hash) REFERENCES commits (hash) ON DELETE CASCADE
) STRICT;
CREATE INDEX idx_commit_links_parent_child
ON commit_links (parent, child);
CREATE INDEX idx_run_measurements_metric_id_value
ON run_measurements (metric, id, value);

View file

@ -68,12 +68,12 @@ async fn save_work(
.execute(&mut *conn)
.await?;
for (name, measurement) in run.measurements {
for (metric, measurement) in run.measurements {
sqlx::query!(
"\
INSERT INTO run_measurements ( \
id, \
name, \
metric, \
value, \
stddev, \
unit, \
@ -82,7 +82,7 @@ async fn save_work(
VALUES (?, ?, ?, ?, ?, ?) \
",
run.id,
name,
metric,
measurement.value,
measurement.stddev,
measurement.unit,

View file

@ -67,6 +67,9 @@ pub async fn get_graph_data(
// The SQL queries that return one result per commit *must* return the same
// amount of rows in the same order!
// TODO Order queries by hash only
// TODO After topo sort, do a stable sort by committer date
let unsorted_hashes = sqlx::query_scalar!(
"\
SELECT hash FROM commits \
@ -140,7 +143,7 @@ pub async fn get_graph_data(
SELECT hash, value, MAX(start) \
FROM runs \
JOIN run_measurements USING (id) \
WHERE name = ? \
WHERE metric = ? \
GROUP BY hash \
) \
SELECT value \

View file

@ -21,7 +21,7 @@ use crate::{
};
struct Measurement {
name: String,
metric: String,
value: String,
stddev: String,
unit: String,
@ -81,20 +81,20 @@ async fn from_finished_run(
let measurements = sqlx::query!(
"\
SELECT \
name, \
metric, \
value, \
stddev, \
unit, \
direction \
FROM run_measurements \
WHERE id = ? \
ORDER BY name ASC \
ORDER BY metric ASC \
",
id,
)
.fetch(db)
.map_ok(|r| Measurement {
name: r.name,
metric: r.metric,
value: util::format_value(r.value),
stddev: r.stddev.map(util::format_value).unwrap_or_default(),
unit: r.unit.unwrap_or_default(),

View file

@ -44,7 +44,7 @@
<tbody>
{% for mm in measurements %}
<tr>
<td>{{ mm.name }}</td>
<td>{{ mm.metric }}</td>
<td>{{ mm.value }}</td>
<td>{{ mm.stddev }}</td>
<td>{{ mm.unit }}</td>