From e045e0f7ae6847bf1d48f8c97208afc62b46d45b Mon Sep 17 00:00:00 2001 From: Googol Lee Date: Thu, 2 Jan 2025 23:02:19 +0100 Subject: [PATCH] Fix sqlite fk configuration and enable all tests for sqlite. Enable detail SQL log in tests (#1151) * Fix sqlite fk configuration and enable all tests for sqlite. * Add default severity to golangci-lint config. --- api/.golangci.yml | 2 +- api/database/database.go | 6 +----- .../scanner_tasks/cleanup_tasks/cleanup_media_test.go | 6 ------ api/test_utils/test_db_manager.go | 5 ++++- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/api/.golangci.yml b/api/.golangci.yml index 89bf8b5e..be245fde 100644 --- a/api/.golangci.yml +++ b/api/.golangci.yml @@ -401,7 +401,7 @@ severity: # `@linter` can be used as severity value to keep the severity from linters (e.g. revive, gosec, ...) # # Default: "" - #default-severity: error + default-severity: error # If set to true `severity-rules` regular expressions become case-sensitive. # Default: false #case-sensitive: true diff --git a/api/database/database.go b/api/database/database.go index 2b71bda7..aee7cb79 100644 --- a/api/database/database.go +++ b/api/database/database.go @@ -65,6 +65,7 @@ func GetSqliteAddress(path string) (*url.URL, error) { // queryValues.Add("_busy_timeout", "60000") // 1 minute queryValues.Add("_journal_mode", "WAL") // Write-Ahead Logging (WAL) mode queryValues.Add("_locking_mode", "NORMAL") // allows concurrent reads and writes + queryValues.Add("_foreign_keys", "ON") // Enforc foreign key constraints. address.RawQuery = queryValues.Encode() // log.Panicf("%s", address.String()) @@ -104,11 +105,6 @@ func ConfigureDatabase(config *gorm.Config) (*gorm.DB, error) { return nil, err } - // Manually enable foreign keys for sqlite, as this isn't done by default - if drivers.SQLITE.MatchDatabase(db) { - db.Exec("PRAGMA foreign_keys = ON") - } - return db, nil } diff --git a/api/scanner/scanner_tasks/cleanup_tasks/cleanup_media_test.go b/api/scanner/scanner_tasks/cleanup_tasks/cleanup_media_test.go index 6dcb06e4..5869882e 100644 --- a/api/scanner/scanner_tasks/cleanup_tasks/cleanup_media_test.go +++ b/api/scanner/scanner_tasks/cleanup_tasks/cleanup_media_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/otiai10/copy" - "github.com/photoview/photoview/api/database/drivers" "github.com/photoview/photoview/api/graphql/models" "github.com/photoview/photoview/api/scanner/face_detection" "github.com/photoview/photoview/api/test_utils" @@ -22,11 +21,6 @@ func TestCleanupMedia(t *testing.T) { test_utils.FilesystemTest(t) db := test_utils.DatabaseTest(t) - // Sqlite doesn't seem to support foreign key cascading - if drivers.SQLITE.MatchDatabase(db) { - t.SkipNow() - } - if !assert.NoError(t, face_detection.InitializeFaceDetector(db)) { return } diff --git a/api/test_utils/test_db_manager.go b/api/test_utils/test_db_manager.go index ff108285..24ae58a0 100644 --- a/api/test_utils/test_db_manager.go +++ b/api/test_utils/test_db_manager.go @@ -4,6 +4,7 @@ import ( "github.com/photoview/photoview/api/database" "github.com/pkg/errors" "gorm.io/gorm" + "gorm.io/gorm/logger" ) type TestDBManager struct { @@ -39,7 +40,9 @@ func (dbm *TestDBManager) Close() error { } func (dbm *TestDBManager) setup() error { - config := gorm.Config{} + config := gorm.Config{ + Logger: logger.Default.LogMode(logger.Info), + } db, err := database.ConfigureDatabase(&config) if err != nil { return errors.Wrap(err, "configure test database")