Skip to content

Commit

Permalink
make code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Dec 31, 2023
1 parent b80e7de commit a6a7d7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion models/db/collation.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ func preprocessDatabaseCollation(x *xorm.Engine) {
}

if len(r.InconsistentCollationColumns) > 0 {
log.Error("There are %d table columns have inconsistent collation, they should use %q. Please go to admin panel Self Check page or refer to Gitea document", len(r.InconsistentCollationColumns), r.DatabaseCollation)
log.Error("There are %d table columns using inconsistent collation, they should use %q. Please go to admin panel Self Check page", len(r.InconsistentCollationColumns), r.DatabaseCollation)
}
}
35 changes: 17 additions & 18 deletions tests/integration/db_collation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,31 @@ type TestCollationTbl struct {
func TestDatabaseCollation(t *testing.T) {
x := db.GetEngine(db.DefaultContext).(*xorm.Engine)

// all created tables should use case-sensitive collation by default
if !setting.Database.Type.IsMSSQL() {
_, _ = x.Exec("DROP TABLE IF EXISTS test_collation_tbl")
err := x.Sync(&TestCollationTbl{})
assert.NoError(t, err)
_, _ = x.Exec("INSERT INTO test_collation_tbl (txt) VALUES ('main')")
_, _ = x.Exec("INSERT INTO test_collation_tbl (txt) VALUES ('Main')")
_, _ = x.Exec("INSERT INTO test_collation_tbl (txt) VALUES ('main')")
cnt, err := x.Count(&TestCollationTbl{})
assert.NoError(t, err)
assert.EqualValues(t, 2, cnt)
_, _ = x.Exec("DROP TABLE IF EXISTS test_collation_tbl")
// there are blockers for MSSQL to use case-sensitive collation, see the comments in db/collation.go
if setting.Database.Type.IsMSSQL() {
t.Skip("there are blockers for MSSQL to use case-sensitive collation")
return
}

// all created tables should use case-sensitive collation by default
_, _ = x.Exec("DROP TABLE IF EXISTS test_collation_tbl")
err := x.Sync(&TestCollationTbl{})
assert.NoError(t, err)
_, _ = x.Exec("INSERT INTO test_collation_tbl (txt) VALUES ('main')")
_, _ = x.Exec("INSERT INTO test_collation_tbl (txt) VALUES ('Main')")
_, _ = x.Exec("INSERT INTO test_collation_tbl (txt) VALUES ('main')")
cnt, err := x.Count(&TestCollationTbl{})
assert.NoError(t, err)
assert.EqualValues(t, 2, cnt)
_, _ = x.Exec("DROP TABLE IF EXISTS test_collation_tbl")

// by default, SQLite3 and PostgreSQL are using case-sensitive collations, but MySQL and MSSQL are not
// the following tests are only for MySQL and MSSQL
if !setting.Database.Type.IsMySQL() && !setting.Database.Type.IsMSSQL() {
t.Skip("only MySQL and MSSQL requires the case-sensitive collation check at the moment")
return
}

// but there are blockers for MSSQL to use case-sensitive collation, see the comments in db/collation.go
if !setting.Database.Type.IsMySQL() {
t.Skip("there are blockers for MSSQL to use case-sensitive collation")
return
}

t.Run("Default startup makes database collation case-sensitive", func(t *testing.T) {
r, err := db.CheckCollations(x)
assert.NoError(t, err)
Expand Down

0 comments on commit a6a7d7e

Please sign in to comment.