Skip to content

Commit ada1903

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix-navbar
2 parents 4d4b9ba + 1c9b022 commit ada1903

10 files changed

+247
-221
lines changed

models/auth/source_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"code.gitea.io/gitea/modules/json"
1414

1515
"github.com/stretchr/testify/assert"
16+
"github.com/stretchr/testify/require"
17+
"xorm.io/xorm"
1618
"xorm.io/xorm/schemas"
1719
)
1820

@@ -54,7 +56,8 @@ func TestDumpAuthSource(t *testing.T) {
5456

5557
sb := new(strings.Builder)
5658

57-
db.DumpTables([]*schemas.Table{authSourceSchema}, sb)
58-
59+
// TODO: this test is quite hacky, it should use a low-level "select" (without model processors) but not a database dump
60+
engine := db.GetEngine(db.DefaultContext).(*xorm.Engine)
61+
require.NoError(t, engine.DumpTables([]*schemas.Table{authSourceSchema}, sb))
5962
assert.Contains(t, sb.String(), `"Provider":"ConvertibleSourceName"`)
6063
}

models/db/collation.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func CheckCollations(x *xorm.Engine) (*CheckCollationsResult, error) {
140140
}
141141

142142
func CheckCollationsDefaultEngine() (*CheckCollationsResult, error) {
143-
return CheckCollations(x)
143+
return CheckCollations(xormEngine)
144144
}
145145

146146
func alterDatabaseCollation(x *xorm.Engine, collation string) error {

models/db/context.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func GetEngine(ctx context.Context) Engine {
9494
if e := getExistingEngine(ctx); e != nil {
9595
return e
9696
}
97-
return x.Context(ctx)
97+
return xormEngine.Context(ctx)
9898
}
9999

100100
// getExistingEngine gets an existing db Engine/Statement from this context or returns nil
@@ -155,7 +155,7 @@ func TxContext(parentCtx context.Context) (*Context, Committer, error) {
155155
return newContext(parentCtx, sess), &halfCommitter{committer: sess}, nil
156156
}
157157

158-
sess := x.NewSession()
158+
sess := xormEngine.NewSession()
159159
if err := sess.Begin(); err != nil {
160160
_ = sess.Close()
161161
return nil, nil, err
@@ -179,7 +179,7 @@ func WithTx(parentCtx context.Context, f func(ctx context.Context) error) error
179179
}
180180

181181
func txWithNoCheck(parentCtx context.Context, f func(ctx context.Context) error) error {
182-
sess := x.NewSession()
182+
sess := xormEngine.NewSession()
183183
defer sess.Close()
184184
if err := sess.Begin(); err != nil {
185185
return err
@@ -322,7 +322,7 @@ func CountByBean(ctx context.Context, bean any) (int64, error) {
322322

323323
// TableName returns the table name according a bean object
324324
func TableName(bean any) string {
325-
return x.TableName(bean)
325+
return xormEngine.TableName(bean)
326326
}
327327

328328
// InTransaction returns true if the engine is in a transaction otherwise return false

models/db/convert.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,30 @@ import (
1616

1717
// ConvertDatabaseTable converts database and tables from utf8 to utf8mb4 if it's mysql and set ROW_FORMAT=dynamic
1818
func ConvertDatabaseTable() error {
19-
if x.Dialect().URI().DBType != schemas.MYSQL {
19+
if xormEngine.Dialect().URI().DBType != schemas.MYSQL {
2020
return nil
2121
}
2222

23-
r, err := CheckCollations(x)
23+
r, err := CheckCollations(xormEngine)
2424
if err != nil {
2525
return err
2626
}
2727

28-
_, err = x.Exec(fmt.Sprintf("ALTER DATABASE `%s` CHARACTER SET utf8mb4 COLLATE %s", setting.Database.Name, r.ExpectedCollation))
28+
_, err = xormEngine.Exec(fmt.Sprintf("ALTER DATABASE `%s` CHARACTER SET utf8mb4 COLLATE %s", setting.Database.Name, r.ExpectedCollation))
2929
if err != nil {
3030
return err
3131
}
3232

33-
tables, err := x.DBMetas()
33+
tables, err := xormEngine.DBMetas()
3434
if err != nil {
3535
return err
3636
}
3737
for _, table := range tables {
38-
if _, err := x.Exec(fmt.Sprintf("ALTER TABLE `%s` ROW_FORMAT=dynamic", table.Name)); err != nil {
38+
if _, err := xormEngine.Exec(fmt.Sprintf("ALTER TABLE `%s` ROW_FORMAT=dynamic", table.Name)); err != nil {
3939
return err
4040
}
4141

42-
if _, err := x.Exec(fmt.Sprintf("ALTER TABLE `%s` CONVERT TO CHARACTER SET utf8mb4 COLLATE %s", table.Name, r.ExpectedCollation)); err != nil {
42+
if _, err := xormEngine.Exec(fmt.Sprintf("ALTER TABLE `%s` CONVERT TO CHARACTER SET utf8mb4 COLLATE %s", table.Name, r.ExpectedCollation)); err != nil {
4343
return err
4444
}
4545
}
@@ -49,11 +49,11 @@ func ConvertDatabaseTable() error {
4949

5050
// ConvertVarcharToNVarchar converts database and tables from varchar to nvarchar if it's mssql
5151
func ConvertVarcharToNVarchar() error {
52-
if x.Dialect().URI().DBType != schemas.MSSQL {
52+
if xormEngine.Dialect().URI().DBType != schemas.MSSQL {
5353
return nil
5454
}
5555

56-
sess := x.NewSession()
56+
sess := xormEngine.NewSession()
5757
defer sess.Close()
5858
res, err := sess.QuerySliceString(`SELECT 'ALTER TABLE ' + OBJECT_NAME(SC.object_id) + ' MODIFY SC.name NVARCHAR(' + CONVERT(VARCHAR(5),SC.max_length) + ')'
5959
FROM SYS.columns SC

0 commit comments

Comments
 (0)