mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Fix unique folder migration error (#4170)
This commit is contained in:
@@ -2,6 +2,8 @@ package migrations
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -60,6 +62,19 @@ func (m *schema52Migrator) migrate(ctx context.Context) error {
|
|||||||
|
|
||||||
logger.Infof("correcting folder path %s to %s", folderPath, correctPath)
|
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 && !errors.Is(isEmptyErr, sql.ErrNoRows) {
|
||||||
|
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 already exists, skipping...", correctPath)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := m.db.Exec("UPDATE folders SET path = ? WHERE id = ?", correctPath, id); err != nil {
|
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)
|
return fmt.Errorf("error updating folder path %s to %s: %w", folderPath, correctPath, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user