From 79eee413655c3fadeae4aba1739d0886665ebe76 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Wed, 29 Jan 2025 12:07:29 +0100 Subject: [PATCH] Fix update of weather_forecast The real problem was that i was trying to update the forecast via pgx.Pool, not the acquired connection, therefore it did not have the correct role. I moved everything to a different function where db is not visible in scope, just to make sure i did not fuck up anywhere else. --- cmd/camper-weather/main.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/camper-weather/main.go b/cmd/camper-weather/main.go index 824fcab..351c442 100644 --- a/cmd/camper-weather/main.go +++ b/cmd/camper-weather/main.go @@ -42,13 +42,16 @@ func main() { log.Fatal(err) } defer conn.Release() + updateForecast(context.Background(), conn) +} - if _, err := conn.Exec(context.Background(), "set role to admin"); err != nil { +func updateForecast(ctx context.Context, conn *database.Conn) { + if _, err := conn.Exec(ctx, "set role to admin"); err != nil { log.Fatal(err) } var stationURL string - if err := conn.QueryRow(context.Background(), ` + if err := conn.QueryRow(ctx, ` select station_uri from weather_forecast `).Scan( @@ -68,7 +71,7 @@ func main() { } for _, forecast := range result.Forecasts { - if _, err := db.Exec(context.Background(), ` + if _, err := conn.Exec(ctx, ` update weather_forecast set weather_condition_id = $1 , day_temperature = $2