diff --git a/database/schema.md b/database/schema.md index 8fb9d8657..b8983df76 100644 --- a/database/schema.md +++ b/database/schema.md @@ -258,3 +258,15 @@ aid benchmark error ---------- --- ----- 1 syn-1.0.89 Failed to compile... ``` + +### collector_config + +Information about the collector; it's target architecture, when it was added, whether it is active and when it last had activity denoted by `last_heartbeat_at`. + +``` +sqlite> SELECT * FROM collector_config; + +id target name date_added last_heartbeat_at benchmark_set is_active +--------- ------------------------- ---- ------------- ---------------- --------- ------- +1 aarch64-unknown-linux-gnu foo 2025-06-11... 2025-06-12 17... 2 0 +``` diff --git a/database/src/pool/postgres.rs b/database/src/pool/postgres.rs index 7db2291b0..2a5d49f04 100644 --- a/database/src/pool/postgres.rs +++ b/database/src/pool/postgres.rs @@ -306,6 +306,22 @@ static MIGRATIONS: &[&str] = &[ // Prevent multiple try commits without a `sha` and the same `pr` number // being added to the table r#"CREATE UNIQUE INDEX benchmark_request_pr_commit_type_idx ON benchmark_request (pr, commit_type) WHERE status != 'completed';"#, + r#" + CREATE TABLE IF NOT EXISTS collector_config ( + id SERIAL PRIMARY KEY, + target TEXT NOT NULL, + name TEXT NOT NULL UNIQUE, + date_added TIMESTAMPTZ DEFAULT NOW() NOT NULL, + last_heartbeat_at TIMESTAMPTZ, + benchmark_set INTEGER NOT NULL, + is_active BOOLEAN DEFAULT FALSE NOT NULL, + + -- Given the current setup, we do not want 2 collectors that are active + -- with the same target using the same benchmark set. + CONSTRAINT collector_config_target_bench_active_uniq + UNIQUE (target, benchmark_set, is_active) + ); + "#, ]; #[async_trait::async_trait]