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.
This commit is contained in:
jordi fita mas 2025-01-29 12:07:29 +01:00
parent 9b938dad97
commit 79eee41365
1 changed files with 6 additions and 3 deletions

View File

@ -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