Enable foreign keys for sqlite
This commit is contained in:
parent
c48ede175a
commit
0618b70110
|
@ -103,6 +103,11 @@ func ConfigureDatabase(config *gorm.Config) (*gorm.DB, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Manually enable foreign keys for sqlite, as this isn't done by default
|
||||||
|
if drivers.DatabaseDriver() == drivers.DatabaseDriverSqlite {
|
||||||
|
db.Exec("PRAGMA foreign_keys = ON")
|
||||||
|
}
|
||||||
|
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,11 +108,11 @@ func deleteOldUserAlbums(db *gorm.DB, scannedAlbums []*models.Album, user *model
|
||||||
|
|
||||||
// Delete old albums from database
|
// Delete old albums from database
|
||||||
err := db.Transaction(func(tx *gorm.DB) error {
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
if err := tx.Where("album_id IN ?", deleteAlbumIDs).Delete(&models.UserAlbums{}).Error; err != nil {
|
if err := tx.Where("album_id IN (?)", deleteAlbumIDs).Delete(&models.UserAlbums{}).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := tx.Where("id IN ?", deleteAlbumIDs).Delete(models.Album{}).Error; err != nil {
|
if err := tx.Where("id IN (?)", deleteAlbumIDs).Delete(models.Album{}).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,19 +63,26 @@ func TestCleanupMedia(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
test_utils.RunScannerOnUser(t, db, user1)
|
t.Run("Modify albums", func(t *testing.T) {
|
||||||
assert.Equal(t, 9, countAllMedia())
|
|
||||||
assert.Equal(t, 18, countAllMediaURLs())
|
|
||||||
|
|
||||||
// move faces directory
|
test_utils.RunScannerOnUser(t, db, user1)
|
||||||
assert.NoError(t, os.Rename(path.Join(test_dir, "faces"), path.Join(test_dir, "faces_moved")))
|
assert.Equal(t, 9, countAllMedia())
|
||||||
test_utils.RunScannerAll(t, db)
|
assert.Equal(t, 18, countAllMediaURLs())
|
||||||
assert.Equal(t, 9, countAllMedia())
|
|
||||||
assert.Equal(t, 18, countAllMediaURLs())
|
|
||||||
|
|
||||||
// remove faces_moved directory
|
// move faces directory
|
||||||
assert.NoError(t, os.RemoveAll(path.Join(test_dir, "faces_moved")))
|
assert.NoError(t, os.Rename(path.Join(test_dir, "faces"), path.Join(test_dir, "faces_moved")))
|
||||||
test_utils.RunScannerAll(t, db)
|
test_utils.RunScannerAll(t, db)
|
||||||
assert.Equal(t, 3, countAllMedia())
|
assert.Equal(t, 9, countAllMedia())
|
||||||
assert.Equal(t, 6, countAllMediaURLs())
|
assert.Equal(t, 18, countAllMediaURLs())
|
||||||
|
|
||||||
|
// remove faces_moved directory
|
||||||
|
assert.NoError(t, os.RemoveAll(path.Join(test_dir, "faces_moved")))
|
||||||
|
test_utils.RunScannerAll(t, db)
|
||||||
|
assert.Equal(t, 3, countAllMedia())
|
||||||
|
assert.Equal(t, 6, countAllMediaURLs())
|
||||||
|
})
|
||||||
|
|
||||||
|
// t.Run("Modify images", func(t *testing.T) {
|
||||||
|
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,13 +66,13 @@ func (v EnvironmentVariable) GetBool() bool {
|
||||||
|
|
||||||
// ShouldServeUI whether or not the "serve ui" option is enabled
|
// ShouldServeUI whether or not the "serve ui" option is enabled
|
||||||
func ShouldServeUI() bool {
|
func ShouldServeUI() bool {
|
||||||
return EnvServeUI.GetValue() == "1"
|
return EnvServeUI.GetBool()
|
||||||
}
|
}
|
||||||
|
|
||||||
// DevelopmentMode describes whether or not the server is running in development mode,
|
// DevelopmentMode describes whether or not the server is running in development mode,
|
||||||
// and should thus print debug informations and enable other features related to developing.
|
// and should thus print debug informations and enable other features related to developing.
|
||||||
func DevelopmentMode() bool {
|
func DevelopmentMode() bool {
|
||||||
return EnvDevelopmentMode.GetValue() == "1"
|
return EnvDevelopmentMode.GetBool()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UIPath returns the value from where the static UI files are located if SERVE_UI=1
|
// UIPath returns the value from where the static UI files are located if SERVE_UI=1
|
||||||
|
|
Loading…
Reference in New Issue