Skip to content

Commit

Permalink
Fix unique folder migration error
Browse files Browse the repository at this point in the history
  • Loading branch information
WithoutPants committed Oct 3, 2023
1 parent 0dbe3e6 commit 15b24c1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/sqlite/migrations/52_postmigrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package migrations

import (
"context"
"database/sql"
"fmt"
"path/filepath"
"strings"
Expand Down Expand Up @@ -60,6 +61,19 @@ func (m *schema52Migrator) migrate(ctx context.Context) error {

logger.Infof("correcting folder path %s to %s", folderPath, correctPath)

// ensure the correct path is unique
var v int
isEmptyErr := m.db.Get(&v, "SELECT 1 FROM folders WHERE path = ?", correctPath)
if isEmptyErr != nil && isEmptyErr != sql.ErrNoRows {

Check failure on line 67 in pkg/sqlite/migrations/52_postmigrate.go

View workflow job for this annotation

GitHub Actions / lint

comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
return fmt.Errorf("error checking if correct path %s is unique: %w", correctPath, isEmptyErr)
}

if isEmptyErr == nil {
// correct path is not unique, log and skip
logger.Warnf("correct path %s is not unique, skipping...", correctPath)
continue
}

if _, err := m.db.Exec("UPDATE folders SET path = ? WHERE id = ?", correctPath, id); err != nil {
return fmt.Errorf("error updating folder path %s to %s: %w", folderPath, correctPath, err)
}
Expand Down

0 comments on commit 15b24c1

Please sign in to comment.