Skip to content

Commit c61b902

Browse files
authored
Upgrade xorm to v1.0.0 (go-gitea#10646)
* Upgrade xorm to v1.0.0 * small nit * Fix tests * Update xorm * Update xorm * fix go.sum * fix test * Fix bug when dump * Fix bug * update xorm to latest * Fix migration test * update xorm to latest * Fix import order * Use xorm tag
1 parent dcaa564 commit c61b902

File tree

154 files changed

+7175
-5942
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+7175
-5942
lines changed

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ require (
116116
gopkg.in/testfixtures.v2 v2.5.0
117117
mvdan.cc/xurls/v2 v2.1.0
118118
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
119-
xorm.io/builder v0.3.6
120-
xorm.io/core v0.7.3
121-
xorm.io/xorm v0.8.2-0.20200120024500-c37aff9b3a4a
119+
xorm.io/builder v0.3.7
120+
xorm.io/xorm v1.0.0
122121
)

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ gitea.com/macaron/session v0.0.0-20191207215012-613cebf0674d h1:XLww3CvnFZkXVwau
3939
gitea.com/macaron/session v0.0.0-20191207215012-613cebf0674d/go.mod h1:FanKy3WjWb5iw/iZBPk4ggoQT9FcM6bkBPvmDmsH6tY=
4040
gitea.com/macaron/toolbox v0.0.0-20190822013122-05ff0fc766b7 h1:N9QFoeNsUXLhl14mefLzGluqV7w2mGU3u+iZU+jCeWk=
4141
gitea.com/macaron/toolbox v0.0.0-20190822013122-05ff0fc766b7/go.mod h1:kgsbFPPS4P+acDYDOPDa3N4IWWOuDJt5/INKRUz7aks=
42+
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
43+
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
4244
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
4345
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4446
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
@@ -793,11 +795,11 @@ strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251 h1:mUcz5b3
793795
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251/go.mod h1:FJGmPh3vz9jSos1L/F91iAgnC/aejc0wIIrF2ZwJxdY=
794796
xorm.io/builder v0.3.6 h1:ha28mQ2M+TFx96Hxo+iq6tQgnkC9IZkM6D8w9sKHHF8=
795797
xorm.io/builder v0.3.6/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU=
798+
xorm.io/builder v0.3.7 h1:2pETdKRK+2QG4mLX4oODHEhn5Z8j1m8sXa7jfu+/SZI=
799+
xorm.io/builder v0.3.7/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
796800
xorm.io/core v0.7.2 h1:mEO22A2Z7a3fPaZMk6gKL/jMD80iiyNwRrX5HOv3XLw=
797801
xorm.io/core v0.7.2/go.mod h1:jJfd0UAEzZ4t87nbQYtVjmqpIODugN6PD2D9E+dJvdM=
798-
xorm.io/core v0.7.3 h1:W8ws1PlrnkS1CZU1YWaYLMQcQilwAmQXU0BJDJon+H0=
799-
xorm.io/core v0.7.3/go.mod h1:jJfd0UAEzZ4t87nbQYtVjmqpIODugN6PD2D9E+dJvdM=
800802
xorm.io/xorm v0.8.0 h1:iALxgJrX8O00f8Jk22GbZwPmxJNgssV5Mv4uc2HL9PM=
801803
xorm.io/xorm v0.8.0/go.mod h1:ZkJLEYLoVyg7amJK/5r779bHyzs2AU8f8VMiP6BM7uY=
802-
xorm.io/xorm v0.8.2-0.20200120024500-c37aff9b3a4a h1:hzGd080rlkZ5a7v6Tr3x8PJJnWPfKxGMMl92c8DNcww=
803-
xorm.io/xorm v0.8.2-0.20200120024500-c37aff9b3a4a/go.mod h1:ZkJLEYLoVyg7amJK/5r779bHyzs2AU8f8VMiP6BM7uY=
804+
xorm.io/xorm v1.0.0 h1:ceiwUTrJHqfNFxIUcWjkcbz6kt7sINf2dOXlgLLhaQM=
805+
xorm.io/xorm v1.0.0/go.mod h1:o4vnEsQ5V2F1/WK6w4XTwmiWJeGj82tqjAnHe44wVHY=

models/access.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]*userAcces
207207
// Delete old accesses and insert new ones for repository.
208208
if _, err = e.Delete(&Access{RepoID: repo.ID}); err != nil {
209209
return fmt.Errorf("delete old accesses: %v", err)
210-
} else if _, err = e.Insert(newAccesses); err != nil {
210+
}
211+
if len(newAccesses) == 0 {
212+
return nil
213+
}
214+
215+
if _, err = e.Insert(newAccesses); err != nil {
211216
return fmt.Errorf("insert new accesses: %v", err)
212217
}
213218
return nil

models/list_options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ func (opts ListOptions) getPaginatedSession() *xorm.Session {
2525
func (opts ListOptions) setSessionPagination(sess *xorm.Session) *xorm.Session {
2626
opts.setDefaultValues()
2727

28+
if opts.PageSize <= 0 {
29+
return sess
30+
}
2831
return sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
2932
}
3033

models/log.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"code.gitea.io/gitea/modules/log"
1111

12-
"xorm.io/core"
12+
xormlog "xorm.io/xorm/log"
1313
)
1414

1515
// XORMLogBridge a logger bridge from Logger to xorm
@@ -19,7 +19,7 @@ type XORMLogBridge struct {
1919
}
2020

2121
// NewXORMLogger inits a log bridge for xorm
22-
func NewXORMLogger(showSQL bool) core.ILogger {
22+
func NewXORMLogger(showSQL bool) xormlog.Logger {
2323
return &XORMLogBridge{
2424
showSQL: showSQL,
2525
logger: log.GetLogger("xorm"),
@@ -72,22 +72,22 @@ func (l *XORMLogBridge) Warnf(format string, v ...interface{}) {
7272
}
7373

7474
// Level get logger level
75-
func (l *XORMLogBridge) Level() core.LogLevel {
75+
func (l *XORMLogBridge) Level() xormlog.LogLevel {
7676
switch l.logger.GetLevel() {
7777
case log.TRACE, log.DEBUG:
78-
return core.LOG_DEBUG
78+
return xormlog.LOG_DEBUG
7979
case log.INFO:
80-
return core.LOG_INFO
80+
return xormlog.LOG_INFO
8181
case log.WARN:
82-
return core.LOG_WARNING
82+
return xormlog.LOG_WARNING
8383
case log.ERROR, log.CRITICAL:
84-
return core.LOG_ERR
84+
return xormlog.LOG_ERR
8585
}
86-
return core.LOG_OFF
86+
return xormlog.LOG_OFF
8787
}
8888

8989
// SetLevel set the logger level
90-
func (l *XORMLogBridge) SetLevel(lvl core.LogLevel) {
90+
func (l *XORMLogBridge) SetLevel(lvl xormlog.LogLevel) {
9191
}
9292

9393
// ShowSQL set if record SQL

models/login_source.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"code.gitea.io/gitea/modules/timeutil"
2323

2424
"github.com/unknwon/com"
25-
"xorm.io/core"
2625
"xorm.io/xorm"
26+
"xorm.io/xorm/convert"
2727
)
2828

2929
// LoginType represents an login type.
@@ -60,11 +60,11 @@ var SecurityProtocolNames = map[ldap.SecurityProtocol]string{
6060

6161
// Ensure structs implemented interface.
6262
var (
63-
_ core.Conversion = &LDAPConfig{}
64-
_ core.Conversion = &SMTPConfig{}
65-
_ core.Conversion = &PAMConfig{}
66-
_ core.Conversion = &OAuth2Config{}
67-
_ core.Conversion = &SSPIConfig{}
63+
_ convert.Conversion = &LDAPConfig{}
64+
_ convert.Conversion = &SMTPConfig{}
65+
_ convert.Conversion = &PAMConfig{}
66+
_ convert.Conversion = &OAuth2Config{}
67+
_ convert.Conversion = &SSPIConfig{}
6868
)
6969

7070
// LDAPConfig holds configuration for LDAP login source.
@@ -165,10 +165,10 @@ func (cfg *SSPIConfig) ToDB() ([]byte, error) {
165165
type LoginSource struct {
166166
ID int64 `xorm:"pk autoincr"`
167167
Type LoginType
168-
Name string `xorm:"UNIQUE"`
169-
IsActived bool `xorm:"INDEX NOT NULL DEFAULT false"`
170-
IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
171-
Cfg core.Conversion `xorm:"TEXT"`
168+
Name string `xorm:"UNIQUE"`
169+
IsActived bool `xorm:"INDEX NOT NULL DEFAULT false"`
170+
IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
171+
Cfg convert.Conversion `xorm:"TEXT"`
172172

173173
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
174174
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`

models/migrations/v110.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,26 @@
55
package migrations
66

77
import (
8-
"xorm.io/core"
98
"xorm.io/xorm"
9+
"xorm.io/xorm/schemas"
1010
)
1111

1212
func changeReviewContentToText(x *xorm.Engine) error {
13-
14-
if x.Dialect().DBType() == core.MYSQL {
13+
switch x.Dialect().URI().DBType {
14+
case schemas.MYSQL:
1515
_, err := x.Exec("ALTER TABLE review MODIFY COLUMN content TEXT")
1616
return err
17-
}
18-
19-
if x.Dialect().DBType() == core.ORACLE {
17+
case schemas.ORACLE:
2018
_, err := x.Exec("ALTER TABLE review MODIFY content TEXT")
2119
return err
22-
}
23-
24-
if x.Dialect().DBType() == core.MSSQL {
20+
case schemas.MSSQL:
2521
_, err := x.Exec("ALTER TABLE review ALTER COLUMN content TEXT")
2622
return err
27-
}
28-
29-
if x.Dialect().DBType() == core.POSTGRES {
23+
case schemas.POSTGRES:
3024
_, err := x.Exec("ALTER TABLE review ALTER COLUMN content TYPE TEXT")
3125
return err
26+
default:
27+
// SQLite doesn't support ALTER COLUMN, and it seem to already make String to _TEXT_ default so no migration needed
28+
return nil
3229
}
33-
34-
// SQLite doesn't support ALTER COLUMN, and it seem to already make String to _TEXT_ default so no migration needed
35-
return nil
3630
}

models/migrations/v81.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ import (
88
"fmt"
99

1010
"xorm.io/xorm"
11+
"xorm.io/xorm/schemas"
1112
)
1213

1314
func changeU2FCounterType(x *xorm.Engine) error {
1415
var err error
1516

16-
switch x.Dialect().DriverName() {
17-
case "mysql":
17+
switch x.Dialect().URI().DBType {
18+
case schemas.MYSQL:
1819
_, err = x.Exec("ALTER TABLE `u2f_registration` MODIFY `counter` BIGINT")
19-
case "postgres":
20+
case schemas.POSTGRES:
2021
_, err = x.Exec("ALTER TABLE `u2f_registration` ALTER COLUMN `counter` SET DATA TYPE bigint")
21-
case "mssql":
22+
case schemas.MSSQL:
2223
_, err = x.Exec("ALTER TABLE `u2f_registration` ALTER COLUMN `counter` BIGINT")
2324
}
2425

models/models.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import (
1515

1616
// Needed for the MySQL driver
1717
_ "github.com/go-sql-driver/mysql"
18-
"xorm.io/core"
1918
"xorm.io/xorm"
19+
"xorm.io/xorm/names"
20+
"xorm.io/xorm/schemas"
2021

2122
// Needed for the Postgresql driver
2223
_ "github.com/lib/pq"
@@ -127,7 +128,7 @@ func init() {
127128

128129
gonicNames := []string{"SSL", "UID"}
129130
for _, name := range gonicNames {
130-
core.LintGonicMapper[name] = true
131+
names.LintGonicMapper[name] = true
131132
}
132133
}
133134

@@ -152,8 +153,7 @@ func NewTestEngine(x *xorm.Engine) (err error) {
152153
return fmt.Errorf("Connect to database: %v", err)
153154
}
154155

155-
x.ShowExecTime(true)
156-
x.SetMapper(core.GonicMapper{})
156+
x.SetMapper(names.GonicMapper{})
157157
x.SetLogger(NewXORMLogger(!setting.ProdMode))
158158
x.ShowSQL(!setting.ProdMode)
159159
return x.StoreEngine("InnoDB").Sync2(tables...)
@@ -166,8 +166,7 @@ func SetEngine() (err error) {
166166
return fmt.Errorf("Failed to connect to database: %v", err)
167167
}
168168

169-
x.ShowExecTime(true)
170-
x.SetMapper(core.GonicMapper{})
169+
x.SetMapper(names.GonicMapper{})
171170
// WARNING: for serv command, MUST remove the output to os.stdout,
172171
// so use log file to instead print to stdout.
173172
x.SetLogger(NewXORMLogger(setting.Database.LogSQL))
@@ -249,21 +248,26 @@ func Ping() error {
249248

250249
// DumpDatabase dumps all data from database according the special database SQL syntax to file system.
251250
func DumpDatabase(filePath string, dbType string) error {
252-
var tbs []*core.Table
251+
var tbs []*schemas.Table
253252
for _, t := range tables {
254-
t := x.TableInfo(t)
255-
t.Table.Name = t.Name
256-
tbs = append(tbs, t.Table)
253+
t, err := x.TableInfo(t)
254+
if err != nil {
255+
return err
256+
}
257+
tbs = append(tbs, t)
257258
}
258259
if len(dbType) > 0 {
259-
return x.DumpTablesToFile(tbs, filePath, core.DbType(dbType))
260+
return x.DumpTablesToFile(tbs, filePath, schemas.DBType(dbType))
260261
}
261262
return x.DumpTablesToFile(tbs, filePath)
262263
}
263264

264265
// MaxBatchInsertSize returns the table's max batch insert size
265266
func MaxBatchInsertSize(bean interface{}) int {
266-
t := x.TableInfo(bean)
267+
t, err := x.TableInfo(bean)
268+
if err != nil {
269+
return 50
270+
}
267271
return 999 / len(t.ColumnsSeq())
268272
}
269273

models/org_team.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,12 +1072,14 @@ func UpdateTeamUnits(team *Team, units []TeamUnit) (err error) {
10721072
return err
10731073
}
10741074

1075-
if _, err = sess.Insert(units); err != nil {
1076-
errRollback := sess.Rollback()
1077-
if errRollback != nil {
1078-
log.Error("UpdateTeamUnits sess.Rollback: %v", errRollback)
1075+
if len(units) > 0 {
1076+
if _, err = sess.Insert(units); err != nil {
1077+
errRollback := sess.Rollback()
1078+
if errRollback != nil {
1079+
log.Error("UpdateTeamUnits sess.Rollback: %v", errRollback)
1080+
}
1081+
return err
10791082
}
1080-
return err
10811083
}
10821084

10831085
return sess.Commit()

models/repo.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,8 +1417,10 @@ func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes [
14171417
return err
14181418
}
14191419

1420-
if _, err = sess.Insert(units); err != nil {
1421-
return err
1420+
if len(units) > 0 {
1421+
if _, err = sess.Insert(units); err != nil {
1422+
return err
1423+
}
14221424
}
14231425

14241426
return sess.Commit()

models/repo_unit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import (
1010
"code.gitea.io/gitea/modules/timeutil"
1111

1212
"github.com/unknwon/com"
13-
"xorm.io/core"
1413
"xorm.io/xorm"
14+
"xorm.io/xorm/convert"
1515
)
1616

1717
// RepoUnit describes all units of a repository
1818
type RepoUnit struct {
1919
ID int64
2020
RepoID int64 `xorm:"INDEX(s)"`
2121
Type UnitType `xorm:"INDEX(s)"`
22-
Config core.Conversion `xorm:"TEXT"`
22+
Config convert.Conversion `xorm:"TEXT"`
2323
CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"`
2424
}
2525

models/ssh_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ func AddPublicKey(ownerID int64, name, content string, loginSourceID int64) (*Pu
524524
func GetPublicKeyByID(keyID int64) (*PublicKey, error) {
525525
key := new(PublicKey)
526526
has, err := x.
527-
Id(keyID).
527+
ID(keyID).
528528
Get(key)
529529
if err != nil {
530530
return nil, err

models/test_fixtures.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"gopkg.in/testfixtures.v2"
12+
"xorm.io/xorm/schemas"
1213
)
1314

1415
var fixtures *testfixtures.Context
@@ -36,7 +37,7 @@ func LoadFixtures() error {
3637
fmt.Printf("LoadFixtures failed after retries: %v\n", err)
3738
}
3839
// Now if we're running postgres we need to tell it to update the sequences
39-
if x.Dialect().DriverName() == "postgres" {
40+
if x.Dialect().URI().DBType == schemas.POSTGRES {
4041
results, err := x.QueryString(`SELECT 'SELECT SETVAL(' ||
4142
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
4243
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||

models/unit_tests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"github.com/stretchr/testify/assert"
2121
"github.com/unknwon/com"
2222
"gopkg.in/testfixtures.v2"
23-
"xorm.io/core"
2423
"xorm.io/xorm"
24+
"xorm.io/xorm/names"
2525
)
2626

2727
// NonexistentID an ID that will never exist
@@ -92,7 +92,7 @@ func CreateTestEngine(fixturesDir string) error {
9292
if err != nil {
9393
return err
9494
}
95-
x.SetMapper(core.GonicMapper{})
95+
x.SetMapper(names.GonicMapper{})
9696
if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
9797
return err
9898
}

0 commit comments

Comments
 (0)