mirror of
https://github.com/syncthing/syncthing.git
synced 2026-05-24 08:55:19 -04:00
fix(db): only perform foreign key checking when a migration was applied (#10397)
This commit is contained in:
committed by
GitHub
parent
5595113074
commit
a64c5396e9
@@ -125,7 +125,7 @@ func openBase(path string, maxConns int, pragmas, schemaScripts, migrationScript
|
||||
}
|
||||
|
||||
ver, _ := db.getAppliedSchemaVersion(tx)
|
||||
shouldVacuum := false
|
||||
appliedMigrations := false
|
||||
if ver.SchemaVersion > 0 {
|
||||
filter := func(scr string) bool {
|
||||
scr = filepath.Base(scr)
|
||||
@@ -139,7 +139,7 @@ func openBase(path string, maxConns int, pragmas, schemaScripts, migrationScript
|
||||
}
|
||||
if int(n) > ver.SchemaVersion {
|
||||
slog.Info("Applying database migration", slogutil.FilePath(db.baseName), slog.String("script", scr))
|
||||
shouldVacuum = true
|
||||
appliedMigrations = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -162,8 +162,10 @@ func openBase(path string, maxConns int, pragmas, schemaScripts, migrationScript
|
||||
}
|
||||
|
||||
// Finally, ensure nothing we've done along the way has violated key integrity.
|
||||
if _, err := conn.ExecContext(ctx, "PRAGMA foreign_key_check"); err != nil {
|
||||
return nil, wrap(err)
|
||||
if appliedMigrations {
|
||||
if _, err := conn.ExecContext(ctx, "PRAGMA foreign_key_check"); err != nil {
|
||||
return nil, wrap(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +178,7 @@ func openBase(path string, maxConns int, pragmas, schemaScripts, migrationScript
|
||||
return nil, wrap(err)
|
||||
}
|
||||
|
||||
if shouldVacuum {
|
||||
if appliedMigrations {
|
||||
// We applied migrations and should take the opportunity to vaccuum
|
||||
// the database.
|
||||
if err := db.vacuumAndOptimize(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user