diff --git a/cmd/backups/list.go b/cmd/backups/list.go index 7672f60..56424f9 100644 --- a/cmd/backups/list.go +++ b/cmd/backups/list.go @@ -36,7 +36,7 @@ func ListCmd() *cobra.Command { ui.FormatBold, "ID", "Created", "Size", "Schema", ui.ColorReset) fmt.Println() - for _, b := range backups { + for i, b := range backups { var schemaTag string if b.IsUpToDate { schemaTag = fmt.Sprintf("%s%s v%d (current)%s", ui.ColorGreen, ui.EmojiSuccess, b.SchemaVersion, ui.ColorReset) @@ -44,11 +44,17 @@ func ListCmd() *cobra.Command { schemaTag = fmt.Sprintf("%s%s v%d (outdated)%s", ui.ColorYellow, ui.EmojiWarning, b.SchemaVersion, ui.ColorReset) } - fmt.Printf(" %-4d %-28s %-8s %s\n", + var latestTag string + if i == len(backups)-1 { + latestTag = fmt.Sprintf(" %s← latest%s", ui.ColorCyan, ui.ColorReset) + } + + fmt.Printf(" %-4d %-28s %-8s %s%s\n", b.ID, settings.FormatDateTime(b.CreatedAt), ui.FormatFileSize(b.Size), schemaTag, + latestTag, ) } diff --git a/internal/storage/backup.go b/internal/storage/backup.go index 731f3a9..59fa40d 100644 --- a/internal/storage/backup.go +++ b/internal/storage/backup.go @@ -75,7 +75,7 @@ func (d *Database) CreateBackup() (*BackupInfo, error) { }, nil } -// ListBackups returns all backups sorted newest-first with display IDs assigned (1 = newest). +// ListBackups returns all backups sorted oldest-first with display IDs assigned (1 = oldest). func ListBackups() ([]BackupInfo, error) { backupDir, err := GetBackupDir() if err != nil { @@ -118,7 +118,7 @@ func ListBackups() ([]BackupInfo, error) { } sort.Slice(backups, func(i, j int) bool { - return backups[i].CreatedAt.After(backups[j].CreatedAt) + return backups[i].CreatedAt.Before(backups[j].CreatedAt) }) for i := range backups { diff --git a/internal/storage/backup_test.go b/internal/storage/backup_test.go index a139001..99f3b3c 100644 --- a/internal/storage/backup_test.go +++ b/internal/storage/backup_test.go @@ -163,7 +163,7 @@ func TestListBackups_IgnoresNonDBFiles(t *testing.T) { assert.Empty(t, backups) } -func TestListBackups_SortedNewestFirst(t *testing.T) { +func TestListBackups_SortedOldestFirst(t *testing.T) { tmpHome := t.TempDir() t.Setenv("HOME", tmpHome) t.Setenv("USERPROFILE", tmpHome) @@ -190,9 +190,9 @@ func TestListBackups_SortedNewestFirst(t *testing.T) { assert.Equal(t, 1, backups[0].ID) assert.Equal(t, 2, backups[1].ID) - assert.Equal(t, "tmpo-20260102-100000.db", backups[0].Filename) - assert.Equal(t, "tmpo-20260101-100000.db", backups[1].Filename) - assert.True(t, backups[0].CreatedAt.After(backups[1].CreatedAt)) + assert.Equal(t, "tmpo-20260101-100000.db", backups[0].Filename) + assert.Equal(t, "tmpo-20260102-100000.db", backups[1].Filename) + assert.True(t, backups[0].CreatedAt.Before(backups[1].CreatedAt)) } func TestCreateBackup(t *testing.T) {