Skip to content

Commit a8c4c63

Browse files
authored
Merge branch 'main' into cheaper-updates
2 parents d9fdc52 + 7836045 commit a8c4c63

File tree

1 file changed

+6
-4
lines changed
  • crates/corrosion/src/command/consul

1 file changed

+6
-4
lines changed

crates/corrosion/src/command/consul/sync.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ async fn update_hashes(
229229

230230
let services = conn
231231
.prepare(
232-
"SELECT id, name, tags, meta, port, address FROM consul_services WHERE node = ?",
232+
"SELECT id, name, tags, meta, port, address FROM consul_services WHERE node = ? AND source IS NULL",
233233
)?
234234
.query_map([nodename], |row| {
235235
let tag_json: String = row.get(2)?;
@@ -258,7 +258,7 @@ async fn update_hashes(
258258
.map_err(|e| eyre::eyre!("could not query consul_checks' table_info: {e}"))?
259259
.collect::<Result<Vec<_>, _>>()?;
260260

261-
let checks = conn.prepare("SELECT id, name, status, output, service_id, service_name FROM consul_checks WHERE node = ?")?
261+
let checks = conn.prepare("SELECT id, name, status, output, service_id, service_name FROM consul_checks WHERE node = ? AND source IS NULL")?
262262
.query_map([nodename], |row| {
263263
Ok(AgentCheck{
264264
id: row.get(0)?,
@@ -659,7 +659,7 @@ async fn execute(
659659
}
660660

661661
// delete everything that's wrong in the DB! this is useful on restore from a backup...
662-
statements.push(Statement::WithParams("DELETE FROM consul_services WHERE node = ? AND id NOT IN (SELECT id FROM __corro_consul_services)".into(), vec![node.into()]));
662+
statements.push(Statement::WithParams("DELETE FROM consul_services WHERE node = ? AND source IS NULL AND id NOT IN (SELECT id FROM __corro_consul_services)".into(), vec![node.into()]));
663663

664664
let mut check_to_upsert = vec![];
665665
let mut check_to_delete = vec![];
@@ -685,7 +685,7 @@ async fn execute(
685685
}
686686

687687
// delete everything that's wrong in the DB! this is useful on restore from a backup...
688-
statements.push(Statement::WithParams("DELETE FROM consul_checks WHERE node = ? AND id NOT IN (SELECT id FROM __corro_consul_checks)".into(), vec![node.into()]));
688+
statements.push(Statement::WithParams("DELETE FROM consul_checks WHERE node = ? AND source IS NULL AND id NOT IN (SELECT id FROM __corro_consul_checks)".into(), vec![node.into()]));
689689

690690
if !statements.is_empty() {
691691
if let Some(e) = corrosion
@@ -756,6 +756,7 @@ mod tests {
756756
address TEXT NOT NULL DEFAULT '',
757757
updated_at INTEGER NOT NULL DEFAULT 0,
758758
app_id INTEGER AS (CAST(JSON_EXTRACT(meta, '$.app_id') AS INTEGER)),
759+
source TEXT,
759760
760761
PRIMARY KEY (node, id)
761762
);
@@ -769,6 +770,7 @@ mod tests {
769770
status TEXT NOT NULL DEFAULT '',
770771
output TEXT NOT NULL DEFAULT '',
771772
updated_at INTEGER NOT NULL DEFAULT 0,
773+
source TEXT,
772774
PRIMARY KEY (node, id)
773775
);
774776
",

0 commit comments

Comments
 (0)