package main import ( "database/sql" "fmt" "time" ) // SeedLive creates live_streams and co_listening_sessions. func SeedLive(db *sql.DB, cfg Config, users []SeededUser, tracks []SeededTrack) error { fmt.Println("\n═══ LIVE STREAMS ═══") artists := GetArtists(users) if len(artists) == 0 { return nil } // ── 1. Past live streams ───────────────────────────────────────────────── p := NewProgress("live_streams (past)", cfg.PastLiveStreams) liveRows := make([][]interface{}, 0, cfg.PastLiveStreams+cfg.LiveStreams) for i := 0; i < cfg.PastLiveStreams; i++ { artist := artists[rng.Intn(len(artists))] title := pick(liveStreamTitles) desc := fmt.Sprintf("Live session by %s", artist.DisplayName) category := pick([]string{"dj-set", "production", "performance", "tutorial", "q&a"}) startTime := RandomTimeAfter(artist.CreatedAt) viewerCount := PowerLaw(1, 500, 1.5) liveRows = append(liveRows, []interface{}{ newUUID(), artist.ID, title, desc, category, artist.DisplayName, false, viewerCount, "[]", // tags (jsonb) startTime, startTime, startTime, }) } p.Update(cfg.PastLiveStreams) p.Done() // ── 2. Current live streams ────────────────────────────────────────────── p = NewProgress("live_streams (active)", cfg.LiveStreams) for i := 0; i < cfg.LiveStreams && i < len(artists); i++ { artist := artists[i] title := pick(liveStreamTitles) desc := fmt.Sprintf("LIVE NOW: %s", artist.DisplayName) category := pick([]string{"dj-set", "production", "performance"}) startTime := time.Now().Add(-time.Duration(randInt(5, 90)) * time.Minute) viewerCount := randInt(5, 150) liveRows = append(liveRows, []interface{}{ newUUID(), artist.ID, title, desc, category, artist.DisplayName, true, viewerCount, "[]", startTime, startTime, startTime, }) } p.Update(cfg.LiveStreams) p.Done() _, err := BulkInsert(db, "live_streams", "id, user_id, title, description, category, streamer_name, is_live, viewer_count, tags, scheduled_at, created_at, updated_at", liveRows) if err != nil { return fmt.Errorf("insert live_streams: %w", err) } // ── 3. Co-listening sessions ───────────────────────────────────────────── coCount := cfg.PastLiveStreams / 10 if coCount < 5 { coCount = 5 } p = NewProgress("co_listening_sessions", coCount) coRows := make([][]interface{}, 0, coCount) for i := 0; i < coCount && len(tracks) > 0; i++ { host := users[rng.Intn(len(users))] track := tracks[rng.Intn(len(tracks))] createdAt := RandomTimeAfter(host.CreatedAt) expiresAt := createdAt.Add(4 * time.Hour) coRows = append(coRows, []interface{}{ newUUID(), host.ID, track.ID, createdAt, expiresAt, }) } _, _ = BulkInsert(db, "co_listening_sessions", "id, host_id, track_id, created_at, expires_at", coRows) p.Update(coCount) p.Done() return nil }