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
10 changes: 8 additions & 2 deletions cmd/backups/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,25 @@ 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)
} else {
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,
)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/storage/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions internal/storage/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
Loading