mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 03:12:43 +01:00
add tidb support
This commit is contained in:
parent
10de16beb0
commit
aff773f1b9
9 changed files with 44 additions and 12 deletions
|
@ -13,7 +13,7 @@ watch_dirs = [
|
|||
watch_exts = [".go"]
|
||||
build_delay = 1500
|
||||
cmds = [
|
||||
["go", "install", "-tags", "sqlite"],# redis memcache cert pam tidb
|
||||
["go", "build", "-tags", "sqlite"],
|
||||
["go", "install", "-tags", "sqlite tidb"],# redis memcache cert pam
|
||||
["go", "build", "-tags", "sqlite tidb"],
|
||||
["./gogs", "web"]
|
||||
]
|
|
@ -65,7 +65,7 @@ USER = root
|
|||
PASSWD =
|
||||
; For "postgres" only, either "disable", "require" or "verify-full"
|
||||
SSL_MODE = disable
|
||||
; For "sqlite3" only
|
||||
; For "sqlite3" and "tidb"
|
||||
PATH = data/gogs.db
|
||||
|
||||
[admin]
|
||||
|
|
|
@ -65,7 +65,10 @@ db_helper = Please use INNODB engine with utf8_general_ci charset for MySQL.
|
|||
ssl_mode = SSL Mode
|
||||
path = Path
|
||||
sqlite_helper = The file path of SQLite3 database.
|
||||
err_empty_sqlite_path = SQLite3 database path cannot be empty.
|
||||
err_empty_db_path = SQLite3 or TiDB database path cannot be empty.
|
||||
err_invalid_tidb_name = TiDB database name does not allow characters "." and "-".
|
||||
no_admin_and_disable_registration = You cannot disable registration without creating an admin account.
|
||||
err_empty_admin_password = Admin password cannot be empty.
|
||||
|
||||
general_title = Application General Settings
|
||||
app_name = Application Name
|
||||
|
@ -868,7 +871,7 @@ config.db_user = User
|
|||
config.db_ssl_mode = SSL Mode
|
||||
config.db_ssl_mode_helper = (for "postgres" only)
|
||||
config.db_path = Path
|
||||
config.db_path_helper = (for "sqlite3" only)
|
||||
config.db_path_helper = (for "sqlite3" and "tidb")
|
||||
config.service_config = Service Configuration
|
||||
config.register_email_confirm = Require E-mail Confirmation
|
||||
config.disable_register = Disable Registration
|
||||
|
|
|
@ -55,7 +55,7 @@ func regulateTimeZone(t time.Time) time.Time {
|
|||
return t
|
||||
}
|
||||
hour := com.StrTo(zone[2:3]).MustInt()
|
||||
minutes := com.StrTo(zone[3:4]).MustInt()
|
||||
minutes := com.StrTo(zone[3:5]).MustInt()
|
||||
|
||||
if zone[0] == '-' {
|
||||
return t.Add(time.Duration(hour) * time.Hour).Add(time.Duration(minutes) * time.Minute)
|
||||
|
@ -104,6 +104,8 @@ func LoadModelsConfig() {
|
|||
setting.UseMySQL = true
|
||||
case "postgres":
|
||||
setting.UsePostgreSQL = true
|
||||
case "tidb":
|
||||
setting.UseTiDB = true
|
||||
}
|
||||
DbCfg.Host = sec.Key("HOST").String()
|
||||
DbCfg.Name = sec.Key("NAME").String()
|
||||
|
|
|
@ -8,9 +8,11 @@ package models
|
|||
|
||||
import (
|
||||
_ "github.com/go-xorm/tidb"
|
||||
"github.com/ngaut/log"
|
||||
_ "github.com/pingcap/tidb"
|
||||
)
|
||||
|
||||
func init() {
|
||||
EnableTidb = true
|
||||
log.SetLevelByString("error")
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -75,6 +75,7 @@ var (
|
|||
UseSQLite3 bool
|
||||
UseMySQL bool
|
||||
UsePostgreSQL bool
|
||||
UseTiDB bool
|
||||
|
||||
// Webhook settings.
|
||||
Webhook struct {
|
||||
|
|
|
@ -110,7 +110,11 @@ func Install(ctx *middleware.Context) {
|
|||
ctx.Data["CurDbOption"] = "PostgreSQL"
|
||||
case "sqlite3":
|
||||
if models.EnableSQLite3 {
|
||||
ctx.Data["CurDbOption"] = "SQLite3" // Default when enabled.
|
||||
ctx.Data["CurDbOption"] = "SQLite3"
|
||||
}
|
||||
case "tidb":
|
||||
if models.EnableTidb {
|
||||
ctx.Data["CurDbOption"] = "TiDB"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,9 +187,15 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||
models.DbCfg.SSLMode = form.SSLMode
|
||||
models.DbCfg.Path = form.DbPath
|
||||
|
||||
if models.DbCfg.Type == "sqlite3" && len(models.DbCfg.Path) == 0 {
|
||||
if (models.DbCfg.Type == "sqlite3" || models.DbCfg.Type == "tidb") &&
|
||||
len(models.DbCfg.Path) == 0 {
|
||||
ctx.Data["Err_DbPath"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("install.err_empty_sqlite_path"), INSTALL, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("install.err_empty_db_path"), INSTALL, &form)
|
||||
return
|
||||
} else if models.DbCfg.Type == "tidb" &&
|
||||
strings.ContainsAny(path.Base(models.DbCfg.Path), ".-") {
|
||||
ctx.Data["Err_DbPath"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("install.err_invalid_tidb_name"), INSTALL, &form)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -217,7 +227,21 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||
return
|
||||
}
|
||||
|
||||
// Check logic loophole between disable self-registration and no admin account.
|
||||
if form.DisableRegistration && len(form.AdminName) == 0 {
|
||||
ctx.Data["Err_Services"] = true
|
||||
ctx.Data["Err_Admin"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("install.no_admin_and_disable_registration"), INSTALL, form)
|
||||
return
|
||||
}
|
||||
|
||||
// Check admin password.
|
||||
if len(form.AdminName) > 0 && len(form.AdminPasswd) == 0 {
|
||||
ctx.Data["Err_Admin"] = true
|
||||
ctx.Data["Err_AdminPasswd"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_password"), INSTALL, form)
|
||||
return
|
||||
}
|
||||
if form.AdminPasswd != form.AdminConfirmPasswd {
|
||||
ctx.Data["Err_Admin"] = true
|
||||
ctx.Data["Err_AdminPasswd"] = true
|
||||
|
|
|
@ -152,7 +152,7 @@
|
|||
|
||||
<!-- Server and other services -->
|
||||
<div class="ui accordion optional field">
|
||||
<div class="title">
|
||||
<div class="title {{if .Err_Services}}text red{{end}}">
|
||||
<i class="icon dropdown"></i>
|
||||
{{.i18n.Tr "install.server_service_title"}}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue