Skip to content

Commit 81af694

Browse files
committed
cleanup
1 parent 27e292c commit 81af694

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,16 +379,17 @@ func storeProtobufInPostgres(db *sql.DB, payload *protos.Payload) error {
379379
hash := sha256.Sum256(jsonData)
380380
dataHash := fmt.Sprintf("%x", hash)
381381

382-
// Insert into PostgreSQL including data_hash
382+
// Insert into PostgreSQL including data_hash with DO NOTHING on conflict
383383
query := `
384384
INSERT INTO telemetry_data (vin, created_at, data, data_hash)
385385
VALUES ($1, $2, $3, $4)
386386
ON CONFLICT (vin, created_at, data_hash)
387-
DO NOTHING;
387+
DO NOTHING
388388
`
389-
_, err = db.Exec(query, vin, createdAt, jsonData, dataHash)
390-
if err != nil {
389+
if _, err := db.Exec(query, vin, createdAt, jsonData, dataHash); err != nil {
391390
return fmt.Errorf("failed to insert into PostgreSQL: %w", err)
391+
} else {
392+
log.Printf("Attempted to insert data into PostgreSQL for VIN:%s CreatedAt:%s", vin, createdAt.String())
392393
}
393394

394395
// Log successful insertion into PostgreSQL

0 commit comments

Comments
 (0)