goog
This commit is contained in:
@@ -443,8 +443,13 @@ public class DatabaseService {
|
||||
ps.setLong(10, Instant.now().getEpochSecond());
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
// If it fails due to UNIQUE constraint on url, try updating by url instead
|
||||
if (e.getMessage().contains("UNIQUE constraint failed: auctions.url")) {
|
||||
// Handle both PRIMARY KEY and URL constraint failures
|
||||
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 = """
|
||||
UPDATE auctions SET
|
||||
auction_id = ?,
|
||||
@@ -470,7 +475,11 @@ public class DatabaseService {
|
||||
|
||||
int updated = ps.executeUpdate();
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user