Skip to content

Commit a42f4c4

Browse files
Prevent duplicate entries in pull_request_build table
When a rust-timer queue comes back empty and another one is issued, we do not want to add another sha-less entry.
1 parent f63c062 commit a42f4c4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

database/src/pool/postgres.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ static MIGRATIONS: &[&str] = &[
148148
requested timestamptz
149149
);
150150
"#,
151+
// Prevent more than one queued entry per PR without a build
152+
r#"
153+
create unique index on pull_request_build (pr) where complete = false;
154+
"#,
151155
];
152156

153157
#[async_trait::async_trait]
@@ -515,7 +519,7 @@ where
515519
async fn queue_pr(&self, pr: u32) {
516520
self.conn()
517521
.execute(
518-
"insert into pull_request_build (pr, complete, requested) VALUES ($1, false, CURRENT_TIMESTAMP)",
522+
"insert into pull_request_build (pr, complete, requested) VALUES ($1, false, CURRENT_TIMESTAMP) ON CONFLICT DO NOTHING",
519523
&[&(pr as i32)],
520524
)
521525
.await

0 commit comments

Comments
 (0)