Update xorm to v1 (#323)
Fix limit for databases other than sqlite go mod tidy && go mod vendor Remove unneeded break statements Make everything work with the new xorm version Fix xorm logging Fix lint Fix redis init Fix using id field Fix database init for testing Change default database log level Add xorm logger Use const for postgres go mod tidy Merge branch 'master' into update/xorm # Conflicts: # go.mod # go.sum # vendor/modules.txt go mod vendor Fix loading fixtures for postgres Go mod vendor1 Update xorm to version 1 Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/323
This commit is contained in:
11
pkg/db/db.go
11
pkg/db/db.go
@ -21,14 +21,14 @@ import (
|
||||
"code.vikunja.io/api/pkg/log"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
xrc "gitea.com/xorm/xorm-redis-cache"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"xorm.io/core"
|
||||
"xorm.io/xorm"
|
||||
|
||||
xrc "gitea.com/xorm/xorm-redis-cache"
|
||||
"xorm.io/xorm/caches"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql" // Because.
|
||||
_ "github.com/lib/pq" // Because.
|
||||
@ -70,8 +70,7 @@ func CreateDBEngine() (engine *xorm.Engine, err error) {
|
||||
}
|
||||
|
||||
engine.SetMapper(core.GonicMapper{})
|
||||
logger := xorm.NewSimpleLogger(log.GetLogWriter("database"))
|
||||
logger.ShowSQL(config.LogDatabase.GetString() != "off")
|
||||
logger := log.NewXormLogger()
|
||||
engine.SetLogger(logger)
|
||||
|
||||
// Cache
|
||||
@ -79,10 +78,10 @@ func CreateDBEngine() (engine *xorm.Engine, err error) {
|
||||
if config.CacheEnabled.GetBool() {
|
||||
switch config.CacheType.GetString() {
|
||||
case "memory":
|
||||
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), config.CacheMaxElementSize.GetInt())
|
||||
cacher := caches.NewLRUCacher(caches.NewMemoryStore(), config.CacheMaxElementSize.GetInt())
|
||||
engine.SetDefaultCacher(cacher)
|
||||
case "redis":
|
||||
cacher := xrc.NewRedisCacher(config.RedisEnabled.GetString(), config.RedisPassword.GetString(), xrc.DEFAULT_EXPIRATION, engine.Logger())
|
||||
cacher := xrc.NewRedisCacher(config.RedisEnabled.GetString(), config.RedisPassword.GetString(), xrc.DEFAULT_EXPIRATION, log.GetXormLoggerForRedis(logger))
|
||||
engine.SetDefaultCacher(cacher)
|
||||
default:
|
||||
log.Info("Did not find a valid cache type. Caching disabled. Please refer to the docs for poosible cache types.")
|
||||
|
@ -1,6 +1,7 @@
|
||||
- id: 1
|
||||
text: 'task #1'
|
||||
description: 'Lorem Ipsum'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 1
|
||||
@ -16,6 +17,7 @@
|
||||
updated: 1543626724
|
||||
- id: 3
|
||||
text: 'task #3 high prio'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 3
|
||||
@ -24,6 +26,7 @@
|
||||
priority: 100
|
||||
- id: 4
|
||||
text: 'task #4 low prio'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 4
|
||||
@ -32,6 +35,7 @@
|
||||
priority: 1
|
||||
- id: 5
|
||||
text: 'task #5 higher due date'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 5
|
||||
@ -40,6 +44,7 @@
|
||||
due_date_unix: 1543636724
|
||||
- id: 6
|
||||
text: 'task #6 lower due date'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 6
|
||||
@ -48,6 +53,7 @@
|
||||
due_date_unix: 1543616724
|
||||
- id: 7
|
||||
text: 'task #7 with start date'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 7
|
||||
@ -56,6 +62,7 @@
|
||||
start_date_unix: 1544600000
|
||||
- id: 8
|
||||
text: 'task #8 with end date'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 8
|
||||
@ -64,6 +71,7 @@
|
||||
end_date_unix: 1544700000
|
||||
- id: 9
|
||||
text: 'task #9 with start and end date'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 9
|
||||
@ -73,6 +81,7 @@
|
||||
end_date_unix: 1544700000
|
||||
- id: 10
|
||||
text: 'task #10 basic'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 10
|
||||
@ -80,6 +89,7 @@
|
||||
updated: 1543626724
|
||||
- id: 11
|
||||
text: 'task #11 basic'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 11
|
||||
@ -87,6 +97,7 @@
|
||||
updated: 1543626724
|
||||
- id: 12
|
||||
text: 'task #12 basic'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 12
|
||||
@ -94,6 +105,7 @@
|
||||
updated: 1543626724
|
||||
- id: 13
|
||||
text: 'task #13 basic other list'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 2
|
||||
index: 1
|
||||
@ -101,6 +113,7 @@
|
||||
updated: 1543626724
|
||||
- id: 14
|
||||
text: 'task #14 basic other list'
|
||||
done: false
|
||||
created_by_id: 5
|
||||
list_id: 5
|
||||
index: 1
|
||||
@ -108,6 +121,7 @@
|
||||
updated: 1543626724
|
||||
- id: 15
|
||||
text: 'task #15'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 6
|
||||
index: 1
|
||||
@ -115,6 +129,7 @@
|
||||
updated: 1543626724
|
||||
- id: 16
|
||||
text: 'task #16'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 7
|
||||
index: 1
|
||||
@ -122,6 +137,7 @@
|
||||
updated: 1543626724
|
||||
- id: 17
|
||||
text: 'task #17'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 8
|
||||
index: 1
|
||||
@ -129,6 +145,7 @@
|
||||
updated: 1543626724
|
||||
- id: 18
|
||||
text: 'task #18'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 9
|
||||
index: 1
|
||||
@ -136,6 +153,7 @@
|
||||
updated: 1543626724
|
||||
- id: 19
|
||||
text: 'task #19'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 10
|
||||
index: 1
|
||||
@ -143,6 +161,7 @@
|
||||
updated: 1543626724
|
||||
- id: 20
|
||||
text: 'task #20'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 11
|
||||
index: 1
|
||||
@ -150,6 +169,7 @@
|
||||
updated: 1543626724
|
||||
- id: 21
|
||||
text: 'task #21'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 12
|
||||
index: 1
|
||||
@ -157,6 +177,7 @@
|
||||
updated: 1543626724
|
||||
- id: 22
|
||||
text: 'task #22'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 13
|
||||
index: 1
|
||||
@ -164,6 +185,7 @@
|
||||
updated: 1543626724
|
||||
- id: 23
|
||||
text: 'task #23'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 14
|
||||
index: 1
|
||||
@ -171,6 +193,7 @@
|
||||
updated: 1543626724
|
||||
- id: 24
|
||||
text: 'task #24'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 15
|
||||
index: 1
|
||||
@ -178,6 +201,7 @@
|
||||
updated: 1543626724
|
||||
- id: 25
|
||||
text: 'task #25'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 16
|
||||
index: 1
|
||||
@ -185,6 +209,7 @@
|
||||
updated: 1543626724
|
||||
- id: 26
|
||||
text: 'task #26'
|
||||
done: false
|
||||
created_by_id: 6
|
||||
list_id: 17
|
||||
index: 1
|
||||
@ -192,6 +217,7 @@
|
||||
updated: 1543626724
|
||||
- id: 27
|
||||
text: 'task #27 with reminders'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 12
|
||||
@ -208,6 +234,7 @@
|
||||
updated: 1543626724
|
||||
- id: 29
|
||||
text: 'task #29 with parent task (1)'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 14
|
||||
@ -215,6 +242,7 @@
|
||||
updated: 1543626724
|
||||
- id: 30
|
||||
text: 'task #30 with assignees'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 15
|
||||
@ -222,6 +250,7 @@
|
||||
updated: 1543626724
|
||||
- id: 31
|
||||
text: 'task #31 with color'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 16
|
||||
@ -230,6 +259,7 @@
|
||||
updated: 1543626724
|
||||
- id: 32
|
||||
text: 'task #32'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 3
|
||||
index: 1
|
||||
@ -237,6 +267,7 @@
|
||||
updated: 1543626724
|
||||
- id: 33
|
||||
text: 'task #33 with percent done'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 17
|
||||
@ -246,6 +277,7 @@
|
||||
# This task is forbidden for user1
|
||||
- id: 34
|
||||
text: 'task #34'
|
||||
done: false
|
||||
created_by_id: 13
|
||||
list_id: 20
|
||||
index: 20
|
||||
@ -253,6 +285,7 @@
|
||||
updated: 1543626724
|
||||
- id: 35
|
||||
text: 'task #35'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 21
|
||||
index: 1
|
||||
@ -260,6 +293,7 @@
|
||||
updated: 1543626724
|
||||
- id: 36
|
||||
text: 'task #36'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
list_id: 22
|
||||
index: 1
|
||||
|
@ -46,7 +46,7 @@ func CreateTestEngine() (engine *xorm.Engine, err error) {
|
||||
}
|
||||
|
||||
engine.SetMapper(core.GonicMapper{})
|
||||
logger := xorm.NewSimpleLogger(log.GetLogWriter("database"))
|
||||
logger := log.NewXormLogger()
|
||||
logger.ShowSQL(os.Getenv("UNIT_TESTS_VERBOSE") == "1")
|
||||
engine.SetLogger(logger)
|
||||
x = engine
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
var fixtures *testfixtures.Loader
|
||||
@ -73,7 +74,7 @@ func LoadFixtures() error {
|
||||
|
||||
// Copied from https://github.com/go-gitea/gitea/blob/master/models/test_fixtures.go#L39
|
||||
// Now if we're running postgres we need to tell it to update the sequences
|
||||
if x.Dialect().DriverName() == "postgres" {
|
||||
if x.Dialect().URI().DBType == schemas.POSTGRES {
|
||||
results, err := x.QueryString(`SELECT 'SELECT SETVAL(' ||
|
||||
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
|
||||
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||
|
||||
|
Reference in New Issue
Block a user