Update address foreign key when updating the address

This commit is contained in:
Eli Ribble 2026-04-13 19:22:41 +00:00
parent dcab2e1f8f
commit ffedae0373
No known key found for this signature in database

View file

@ -8,6 +8,7 @@ import (
"github.com/Gleipnir-Technology/bob" "github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql" "github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um" "github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/enums"
@ -311,6 +312,21 @@ func publicReportUpdateAddress(ctx context.Context, txn bob.Executor, report *mo
if err != nil { if err != nil {
return fmt.Errorf("update report: %w", err) return fmt.Errorf("update report: %w", err)
} }
_, err = psql.Update(
um.Table("publicreport.report"),
um.SetCol("address_id").To(
psql.Select(
sm.Columns("id"),
sm.From("address"),
sm.Where(psql.Quote("gid").EQ(psql.Arg(address.GID))),
sm.Limit(1),
),
),
um.Where(psql.Quote("publicreport", "report", "id").EQ(psql.Arg(report.ID))),
).Exec(ctx, txn)
if err != nil {
return fmt.Errorf("update report address_id: %w", err)
}
return nil return nil
} }
func publicReportUpdateLocation(ctx context.Context, txn bob.Executor, id int32, location types.Location) error { func publicReportUpdateLocation(ctx context.Context, txn bob.Executor, id int32, location types.Location) error {