Skip to content

Commit ea867d6

Browse files
committed
Add database function to purge an already recorded artifact
1 parent c49e3b2 commit ea867d6

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

database/src/pool.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ pub trait Connection: Send + Sync {
179179
profile: &str,
180180
cache: &str,
181181
) -> Vec<(ArtifactIdNumber, i32)>;
182+
183+
/// Removes all data associated with the given artifact.
184+
async fn purge_artifact(&self, aid: &ArtifactId);
182185
}
183186

184187
#[async_trait::async_trait]

database/src/pool/postgres.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,4 +1380,14 @@ where
13801380
_ => panic!("unknown artifact type: {:?}", ty),
13811381
}
13821382
}
1383+
1384+
async fn purge_artifact(&self, aid: &ArtifactId) {
1385+
// Once we delete the artifact, all data associated with it should also be deleted
1386+
// thanks to ON DELETE CASCADE.
1387+
let info = aid.info();
1388+
self.conn()
1389+
.execute("delete from artifact where name = $1", &[&info.name])
1390+
.await
1391+
.unwrap();
1392+
}
13831393
}

database/src/pool/sqlite.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,4 +1231,13 @@ impl Connection for SqliteConnection {
12311231
.collect::<Result<_, _>>()
12321232
.unwrap()
12331233
}
1234+
1235+
async fn purge_artifact(&self, aid: &ArtifactId) {
1236+
// Once we delete the artifact, all data associated with it should also be deleted
1237+
// thanks to ON DELETE CASCADE.
1238+
let info = aid.info();
1239+
self.raw_ref()
1240+
.execute("delete from artifact where name = ?1", [info.name])
1241+
.unwrap();
1242+
}
12341243
}

0 commit comments

Comments
 (0)