Sync branch magefile with main #104308

Merged
Sybren A. Stüvel merged 85 commits from abelli/flamenco:magefile into magefile 2024-05-13 16:26:32 +02:00
2 changed files with 29 additions and 1 deletions
Showing only changes of commit 7eb5eb68a3 - Show all commits

View File

@ -20,7 +20,7 @@ var defaultConfig = Conf{
Listen: ":8080", Listen: ":8080",
// ListenHTTPS: ":8433", // ListenHTTPS: ":8433",
DatabaseDSN: "flamenco-manager.sqlite", DatabaseDSN: "flamenco-manager.sqlite",
DBIntegrityCheck: 1 * time.Hour, DBIntegrityCheck: 10 * time.Minute,
SSDPDiscovery: true, SSDPDiscovery: true,
LocalManagerStoragePath: "./flamenco-manager-storage", LocalManagerStoragePath: "./flamenco-manager-storage",
SharedStoragePath: "", // Empty string means "first run", and should trigger the config setup assistant. SharedStoragePath: "", // Empty string means "first run", and should trigger the config setup assistant.

View File

@ -78,6 +78,8 @@ func (db *DB) performIntegrityCheck(ctx context.Context) (ok bool) {
log.Debug().Msg("database: performing integrity check") log.Debug().Msg("database: performing integrity check")
db.ensureForeignKeysEnabled()
if !db.pragmaIntegrityCheck(checkCtx) { if !db.pragmaIntegrityCheck(checkCtx) {
return false return false
} }
@ -159,3 +161,29 @@ func (db *DB) pragmaForeignKeyCheck(ctx context.Context) (ok bool) {
return false return false
} }
// ensureForeignKeysEnabled checks whether foreign keys are enabled, and if not,
// tries to enable them.
//
// This is likely caused by either GORM or its embedded SQLite creating a new
// connection to the low-level SQLite driver. Unfortunately the GORM-embedded
// SQLite doesn't have an 'on-connect' callback function to always enable
// foreign keys.
func (db *DB) ensureForeignKeysEnabled() {
fkEnabled, err := db.areForeignKeysEnabled()
if err != nil {
log.Error().AnErr("cause", err).Msg("database: could not check whether foreign keys are enabled")
return
}
if fkEnabled {
return
}
log.Warn().Msg("database: foreign keys are disabled, re-enabling them")
if err := db.pragmaForeignKeys(true); err != nil {
log.Error().AnErr("cause", err).Msg("database: error re-enabling foreign keys")
return
}
}