Restructure db schema

The "commit_links" table is now called "commit_edges".

There is now a "metrics" table that run measurements have a foreign key
to. This provides canonical metric metadata and will speed up the
initial graph page (before any real data arrives). For now, it will be
overwritten with each new run, but more nuanced config options may be
added later.
This commit is contained in:
Joscha 2023-09-01 11:47:16 +02:00
parent 1bae83d116
commit a525e58211
18 changed files with 77 additions and 71 deletions

View file

@ -1,2 +0,0 @@
CREATE INDEX idx_run_measurements_metric
ON run_measurements (metric);

View file

@ -1,5 +0,0 @@
CREATE INDEX idx_commits_hash_reachable
ON commits (hash, reachable);
CREATE INDEX idx_commit_links_child_parent
ON commit_links (child, parent);

View file

@ -9,23 +9,38 @@ CREATE TABLE commits (
new INT NOT NULL DEFAULT 1
) STRICT;
CREATE TABLE commit_links (
CREATE INDEX idx_commits_hash_reachable
ON commits (hash, reachable);
CREATE TABLE commit_edges (
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
FOREIGN KEY (child) REFERENCES commits (hash) ON DELETE CASCADE
) STRICT;
CREATE INDEX idx_commit_edges_parent_child
ON commit_edges (parent, child);
CREATE INDEX idx_commit_edges_child_parent
ON commit_edges (child, parent);
CREATE TABLE refs (
name TEXT NOT NULL PRIMARY KEY,
hash TEXT NOT NULL,
tracked INT NOT NULL DEFAULT 0,
tracked INT NOT NULL DEFAULT 0,
FOREIGN KEY (hash) REFERENCES commits (hash) ON DELETE CASCADE
) STRICT;
CREATE TABLE metrics (
name TEXT NOT NULL PRIMARY KEY,
unit TEXT,
direction INT
) STRICT;
CREATE TABLE runs (
id TEXT NOT NULL PRIMARY KEY,
hash TEXT NOT NULL,
@ -46,16 +61,20 @@ CREATE TABLE run_measurements (
unit TEXT,
PRIMARY KEY (id, metric),
FOREIGN KEY (id) REFERENCES runs (id) ON DELETE CASCADE
FOREIGN KEY (id) REFERENCES runs (id) ON DELETE CASCADE,
FOREIGN KEY (metric) REFERENCES metrics (name) ON UPDATE CASCADE ON DELETE CASCADE
) STRICT;
CREATE INDEX idx_run_measurements_metric_id_value
ON run_measurements (metric, id, value);
CREATE TABLE run_output (
id TEXT NOT NULL,
idx INT NOT NULL,
line INT NOT NULL,
source INT NOT NULL,
text TEXT NOT NULL,
PRIMARY KEY (id, idx),
PRIMARY KEY (id, line),
FOREIGN KEY (id) REFERENCES runs (id) ON DELETE CASCADE
) STRICT;
@ -67,11 +86,5 @@ CREATE TABLE queue (
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_queue_priority_date_hash
ON queue (priority DESC, unixepoch(date) DESC, hash ASC);
CREATE INDEX idx_run_measurements_metric_id_value
ON run_measurements (metric, id, value);