feat(discovery): migration 000017 — nullable bucket_id; model uses *uuid.UUID
This commit is contained in:
@@ -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"`
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE discovered_markets ALTER COLUMN bucket_id DROP NOT NULL;
|
||||
Reference in New Issue
Block a user