goog
This commit is contained in:
@@ -443,8 +443,13 @@ public class DatabaseService {
|
|||||||
ps.setLong(10, Instant.now().getEpochSecond());
|
ps.setLong(10, Instant.now().getEpochSecond());
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
// If it fails due to UNIQUE constraint on url, try updating by url instead
|
// Handle both PRIMARY KEY and URL constraint failures
|
||||||
if (e.getMessage().contains("UNIQUE constraint failed: auctions.url")) {
|
String errMsg = e.getMessage();
|
||||||
|
if (errMsg.contains("UNIQUE constraint failed: auctions.auction_id") ||
|
||||||
|
errMsg.contains("UNIQUE constraint failed: auctions.url") ||
|
||||||
|
errMsg.contains("PRIMARY KEY constraint failed")) {
|
||||||
|
|
||||||
|
// Try updating by URL as fallback (most reliable unique identifier)
|
||||||
var updateByUrlSql = """
|
var updateByUrlSql = """
|
||||||
UPDATE auctions SET
|
UPDATE auctions SET
|
||||||
auction_id = ?,
|
auction_id = ?,
|
||||||
@@ -470,7 +475,11 @@ public class DatabaseService {
|
|||||||
|
|
||||||
int updated = ps.executeUpdate();
|
int updated = ps.executeUpdate();
|
||||||
if (updated == 0) {
|
if (updated == 0) {
|
||||||
log.warn("Could not insert or update auction with url={}, auction_id={}", auction.url(), auction.auctionId());
|
// Auction doesn't exist by URL either - this is unexpected
|
||||||
|
log.warn("Could not insert or update auction with url={}, auction_id={} - constraint violation but no existing record found",
|
||||||
|
auction.url(), auction.auctionId());
|
||||||
|
} else {
|
||||||
|
log.debug("Updated existing auction by URL: {}", auction.url());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user