Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions cmd/genesis-writer/entities_track.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type sourceTrack struct {
IsUnlisted bool
IsDownloadable bool
IsOriginalAvailable bool
ReleaseDate *string
ReleaseDate *time.Time
License *string
ISRC *string
ISWC *string
Expand Down Expand Up @@ -157,7 +157,7 @@ func buildTrackMetadata(t sourceTrack, collaborators []int64) trackMetadataInner
IsUnlisted: t.IsUnlisted,
IsDownloadable: t.IsDownloadable,
IsOriginalAvail: t.IsOriginalAvailable,
ReleaseDate: deref(t.ReleaseDate),
ReleaseDate: fmtReleaseDate(t.ReleaseDate),
License: deref(t.License),
ISRC: deref(t.ISRC),
ISWC: deref(t.ISWC),
Expand Down Expand Up @@ -211,6 +211,21 @@ func buildTrackMetadata(t sourceTrack, collaborators []int64) trackMetadataInner
return inner
}

// fmtReleaseDate emits RFC3339, the format the indexer's parseReleaseDate
// accepts. Selecting release_date::text instead yields Postgres's own
// "2026-09-06 22:06:00", which matches none of the accepted layouts, so the
// indexer silently fell back to block time. That is not a cosmetic date
// difference: a track whose release_date lands in the past is picked up by the
// scheduled-release publisher, which sets is_unlisted = false. On the
// 2026-08-07 snapshot 372 unlisted tracks with a future release date had the
// date rewritten and 368 of them were published early.
func fmtReleaseDate(t *time.Time) string {
if t == nil {
return ""
}
return t.UTC().Format(time.RFC3339)
}

func (w *Writer) writeTracks(ctx context.Context) error {
// Pre-load collaborator lists so Track:Create metadata includes them,
// which causes the ETL to create pending invites automatically.
Expand All @@ -231,7 +246,7 @@ func (w *Writer) writeTracks(ctx context.Context) error {
t.track_cid,
t.cover_art, t.cover_art_sizes, t.preview_cid,
t.is_unlisted, t.is_downloadable, t.is_original_available,
t.release_date::text, t.license, t.isrc, t.iswc, t.bpm, t.musical_key,
t.release_date, t.license, t.isrc, t.iswc, t.bpm, t.musical_key,
t.is_custom_bpm, t.is_custom_musical_key,
t.remix_of, t.stem_of,
t.is_stream_gated, t.stream_conditions,
Expand Down
32 changes: 32 additions & 0 deletions cmd/genesis-writer/release_date_format_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"testing"
"time"
)

// The indexer's parseReleaseDate accepts RFC3339, RFC3339Nano and
// "Mon Jan 02 2006 15:04:05 GMT-0700" -- and nothing else. Selecting
// release_date::text yields Postgres's "2026-09-06 22:06:00", which matches
// none of them, so the indexer silently fell back to block time. A future
// release date rewritten into the past is then picked up by the
// scheduled-release publisher, which sets is_unlisted = false: on the
// 2026-08-07 snapshot that rewrote 372 dates and published 368 unlisted
// tracks early.
func TestReleaseDateIsEmittedInAnAcceptedLayout(t *testing.T) {
rd := time.Date(2026, 9, 6, 22, 6, 0, 0, time.UTC)
got := fmtReleaseDate(&rd)

if _, err := time.Parse(time.RFC3339, got); err != nil {
t.Fatalf("fmtReleaseDate produced %q, which the indexer cannot parse: %v", got, err)
}
if got != "2026-09-06T22:06:00Z" {
t.Errorf("fmtReleaseDate = %q, want %q", got, "2026-09-06T22:06:00Z")
}
if got == "2026-09-06 22:06:00" {
t.Error("emitted Postgres text format, which no accepted layout matches")
}
if fmtReleaseDate(nil) != "" {
t.Errorf("nil release_date = %q, want empty so omitempty drops it", fmtReleaseDate(nil))
}
}