feat(discovery): migration 000017 — nullable bucket_id; model uses *uuid.UUID

This commit is contained in:
2026-04-18 14:30:54 +02:00
parent 507052e375
commit 310673940e
4 changed files with 11 additions and 2 deletions

View File

@@ -27,7 +27,7 @@ type Bucket struct {
// vorjahr_unbestaetigt|abgesagt).
type DiscoveredMarket struct {
ID uuid.UUID `json:"id"`
BucketID uuid.UUID `json:"bucket_id"`
BucketID *uuid.UUID `json:"bucket_id"`
MarktName string `json:"markt_name"`
Stadt string `json:"stadt"`
Bundesland string `json:"bundesland"`

View File

@@ -205,7 +205,7 @@ func (s *Service) processBucketResponse(ctx context.Context, b Bucket, resp Pass
}
dm := DiscoveredMarket{
BucketID: b.ID,
BucketID: &b.ID,
MarktName: m.MarktName,
Stadt: m.Stadt,
Bundesland: m.Bundesland,

View File

@@ -0,0 +1,8 @@
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM discovered_markets WHERE bucket_id IS NULL) THEN
RAISE EXCEPTION 'Cannot revert: % rows have NULL bucket_id (crawler-produced). Resolve manually before rolling back.',
(SELECT COUNT(*) FROM discovered_markets WHERE bucket_id IS NULL);
END IF;
END $$;
ALTER TABLE discovered_markets ALTER COLUMN bucket_id SET NOT NULL;

View File

@@ -0,0 +1 @@
ALTER TABLE discovered_markets ALTER COLUMN bucket_id DROP NOT NULL;