Skip to content

Commit 8413226

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Don't give an error when rebuilding documentation
Previously, postgres would give a duplicate key error when a crate was built more than once: ``` thread 'main' panicked at 'Building documentation failed: Error(Db(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("23505"), message: "duplicate key value violates unique constraint \"compression_rels_release_algorithm_key\"", detail: Some("Key (release, algorithm)=(1, 0) already exists."), hint: None, position: None, where_: None, schema: Some("public"), table: Some("compression_rels"), column: None, datatype: None, constraint: Some("compression_rels_release_algorithm_key"), file: Some("nbtinsert.c"), line: Some(434), routine: Some("_bt_check_unique") }))', src/bin/cratesfyi.rs:321:21 ``` Now, duplicate keys are discarded.
1 parent e9d569f commit 8413226

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/db/add_package.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,10 @@ fn add_compression_into_database<I>(conn: &Connection, algorithms: I, release_id
361361
where
362362
I: Iterator<Item = CompressionAlgorithm>,
363363
{
364-
let sql = "INSERT INTO compression_rels (release, algorithm) VALUES ($1, $2);";
364+
let sql = "
365+
INSERT INTO compression_rels (release, algorithm)
366+
VALUES ($1, $2)
367+
ON CONFLICT DO NOTHING;";
365368
let prepared = conn.prepare_cached(sql)?;
366369
for alg in algorithms {
367370
prepared.execute(&[&release_id, &(alg as i32)])?;

0 commit comments

Comments
 (0)