Fix bug where max episode number across all seasons is used
This commit is contained in:
parent
0fdc3f8de2
commit
0094d52834
@ -17,7 +17,7 @@ func CalculateEpisodeNumbers(db *sql.DB) error {
|
|||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
// First find all years that still need episodes numbers
|
// First find all years that still need episodes numbers
|
||||||
rows, err := tx.Query("select year, max((select max(episode) from videos where year = year)) from videos where episode is null group by year")
|
rows, err := tx.Query("select v.year, max((select max(episode) from videos where year = v.year)) from videos v where episode is null group by year")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error retrieving rows: %w", err)
|
return fmt.Errorf("error retrieving rows: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ func TestCalculateEpisodeNumbers(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.Exec("insert into videos (title, url, year, episode, run) values ('Video A', 'a', 2025, 1, 1), ('Video B', 'b', 2025, null, 2)")
|
_, err = db.Exec("insert into videos (title, url, year, episode, run) values ('Video A', 'a', 2025, 1, 1), ('Video B', 'b', 2025, null, 2), ('Old Video', 'c', 2020, 100, 1)")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user