Skip to content

Commit 150b7e4

Browse files
committed
Support use nvarchar for all varchar columns when using mssql
1 parent ed8e064 commit 150b7e4

File tree

15 files changed

+76
-8
lines changed

15 files changed

+76
-8
lines changed

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ SSL_MODE = disable
378378
; For MySQL only, either "utf8" or "utf8mb4", default is "utf8mb4".
379379
; NOTICE: for "utf8mb4" you must use MySQL InnoDB > 5.6. Gitea is unable to check this.
380380
CHARSET = utf8mb4
381+
; For Mssql only, either "varchar" or "nvarchar", default is "varchar"
382+
; NOTICE: if you changed the config, you have to convert the original columns type manually
383+
DEFAULT_VARCHAR = varchar
381384
; For "sqlite3" and "tidb", use an absolute path when you start gitea as service
382385
PATH = data/gitea.db
383386
; For "sqlite3" only. Query timeout

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
245245
- `verify-ca`: Enable TLS with verification of the database server certificate against its root certificate.
246246
- `verify-full`: Enable TLS and verify the database server name matches the given certificate in either the `Common Name` or `Subject Alternative Name` fields.
247247
- `CHARSET`: **utf8mb4**: For MySQL only, either "utf8" or "utf8mb4". NOTICE: for "utf8mb4" you must use MySQL InnoDB > 5.6. Gitea is unable to check this.
248+
- `DEFAULT_VARCHAR`: **varchar**: For Mssql only, either "varchar" or "nvarchar"; If you changed the config, you have to convert the original columns type manually.
248249
- `PATH`: **data/gitea.db**: For SQLite3 only, the database file path.
249250
- `LOG_SQL`: **true**: Log the executed SQL.
250251
- `DB_RETRIES`: **10**: How many ORM init / DB connect attempts allowed.

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ menu:
8282
- `PASSWD`: 数据库用户密码。
8383
- `SSL_MODE`: MySQL 或 PostgreSQL数据库是否启用SSL模式。
8484
- `CHARSET`: **utf8mb4**: 仅当数据库为 MySQL 时有效, 可以为 "utf8" 或 "utf8mb4"。注意:如果使用 "utf8mb4",你的 MySQL InnoDB 版本必须在 5.6 以上。
85+
- `DEFAULT_VARCHAR`: **varchar**: 仅当数据库为 Mssql 时有效, 可以为 "varchar" 或 "nvarchar"。如果改变了此项配置,你需要手动修改数据库中所有已创建的字段为指定的类型。
8586
- `PATH`: Tidb 或者 SQLite3 数据文件存放路径。
8687
- `LOG_SQL`: **true**: 显示生成的SQL,默认为真。
8788
- `MAX_IDLE_CONNS` **0**: 最大空闲数据库连接

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ require (
120120
mvdan.cc/xurls/v2 v2.1.0
121121
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
122122
xorm.io/builder v0.3.7
123-
xorm.io/xorm v1.0.3
123+
xorm.io/xorm v1.0.4-0.20200718080127-318102c9ff87
124124
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,5 +979,5 @@ xorm.io/core v0.7.2 h1:mEO22A2Z7a3fPaZMk6gKL/jMD80iiyNwRrX5HOv3XLw=
979979
xorm.io/core v0.7.2/go.mod h1:jJfd0UAEzZ4t87nbQYtVjmqpIODugN6PD2D9E+dJvdM=
980980
xorm.io/xorm v0.8.0 h1:iALxgJrX8O00f8Jk22GbZwPmxJNgssV5Mv4uc2HL9PM=
981981
xorm.io/xorm v0.8.0/go.mod h1:ZkJLEYLoVyg7amJK/5r779bHyzs2AU8f8VMiP6BM7uY=
982-
xorm.io/xorm v1.0.3 h1:3dALAohvINu2mfEix5a5x5ZmSVGSljinoSGgvGbaZp0=
983-
xorm.io/xorm v1.0.3/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4=
982+
xorm.io/xorm v1.0.4-0.20200718080127-318102c9ff87 h1:vgc2F0wjD0cyrNrSKiIdWu123wuKkPQI84DZUKvJ6ns=
983+
xorm.io/xorm v1.0.4-0.20200718080127-318102c9ff87/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4=

models/models.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ func getEngine() (*xorm.Engine, error) {
145145
}
146146
if setting.Database.Type == "mysql" {
147147
engine.Dialect().SetParams(map[string]string{"rowFormat": "DYNAMIC"})
148+
} else if setting.Database.Type == "mssql" {
149+
engine.Dialect().SetParams(map[string]string{"DEFAULT_VARCHAR": setting.Database.DefaultVarchar})
148150
}
149151
engine.SetSchema(setting.Database.Schema)
150152
return engine, nil

modules/setting/database.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var (
3535
Path string
3636
LogSQL bool
3737
Charset string
38+
DefaultVarchar string
3839
Timeout int // seconds
3940
UseSQLite3 bool
4041
UseMySQL bool
@@ -47,6 +48,7 @@ var (
4748
ConnMaxLifetime time.Duration
4849
IterateBufferSize int
4950
}{
51+
DefaultVarchar: "varchar",
5052
Timeout: 500,
5153
}
5254
)
@@ -79,6 +81,7 @@ func InitDBConfig() {
7981
Database.Schema = sec.Key("SCHEMA").String()
8082
Database.SSLMode = sec.Key("SSL_MODE").MustString("disable")
8183
Database.Charset = sec.Key("CHARSET").In("utf8", []string{"utf8", "utf8mb4"})
84+
Database.DefaultVarchar = sec.Key("DEFAULT_VARCHAR").In("varchar", []string{"varchar", "nvarchar"})
8285
Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
8386
Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
8487
Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2)

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ strk.kbt.io/projects/go/libravatar
916916
# xorm.io/builder v0.3.7
917917
## explicit
918918
xorm.io/builder
919-
# xorm.io/xorm v1.0.3
919+
# xorm.io/xorm v1.0.4-0.20200718080127-318102c9ff87
920920
## explicit
921921
xorm.io/xorm
922922
xorm.io/xorm/caches

vendor/xorm.io/xorm/.drone.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/xorm.io/xorm/Makefile

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/xorm.io/xorm/dialects/mssql.go

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/xorm.io/xorm/go.sum

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/xorm.io/xorm/interface.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/xorm.io/xorm/log/logger_context.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/xorm.io/xorm/session.go

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)