diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-04-11 01:25:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-11 01:25:19 +0800 |
commit | 62dda96159055ff9d485078f257445b964eb5220 (patch) | |
tree | a8bd161dc92c368bee0e6b58797e23278565cd8b /internal/db/db.go | |
parent | 5753d4cb87388c247e91eaf3ce641d309a45e760 (diff) |
access_token: migrate to GORM and add tests (#6086)
* access_token: migrate to GORM
* Add tests
* Fix tests
* Fix test clock
Diffstat (limited to 'internal/db/db.go')
-rw-r--r-- | internal/db/db.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/internal/db/db.go b/internal/db/db.go index e3796039..27135eba 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -39,7 +39,7 @@ func parsePostgreSQLHostPort(info string) (host, port string) { return host, port } -func parseMSSQLHostPort(info string) (host, port string) { +func parseMSSQLHostPort(info string) (host, port string) { host, port = "127.0.0.1", "1433" if strings.Contains(info, ":") { host = strings.Split(info, ":")[0] @@ -122,6 +122,11 @@ func getLogWriter() (io.Writer, error) { return w, nil } +var tables = []interface{}{ + new(AccessToken), + new(LFSObject), +} + func Init() error { db, err := openDB(conf.Database) if err != nil { @@ -150,16 +155,17 @@ func Init() error { case "mssql": conf.UseMSSQL = true case "sqlite3": - conf.UseMySQL = true + conf.UseSQLite3 = true } - err = db.AutoMigrate(new(LFSObject)).Error + err = db.AutoMigrate(tables...).Error if err != nil { return errors.Wrap(err, "migrate schemes") } + clock := func() time.Time {return time.Now().UTC().Truncate(time.Microsecond)} // Initialize stores, sorted in alphabetical order. - AccessTokens = &accessTokens{DB: db} + AccessTokens = &accessTokens{DB: db, clock: clock} LoginSources = &loginSources{DB: db} LFS = &lfs{DB: db} Perms = &perms{DB: db} |