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.
This commit is contained in:
Googol Lee
2025-01-02 23:02:19 +01:00
committed by GitHub
parent 33ef0981d7
commit e045e0f7ae
4 changed files with 6 additions and 13 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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")