aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordlob <dlob@users.noreply.github.com>2017-02-14 02:50:00 +0100
committer无闻 <u@gogs.io>2017-02-13 20:50:00 -0500
commit5179063e71d7234250209389e6f69db1cd6f0caa (patch)
tree3715ab896c028c4f53b4f6b797600c488727fc42
parentad4bbf517335a6a782def7937de34eed6add6b79 (diff)
Added mssql support. (#3772)
-rw-r--r--models/migrations/migrations.go1
-rw-r--r--models/models.go20
-rw-r--r--modules/setting/setting.go1
-rw-r--r--public/js/gogs.js23
-rw-r--r--routers/install.go6
5 files changed, 37 insertions, 14 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 71a14960..cf3785c6 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -87,6 +87,7 @@ func Migrate(x *xorm.Engine) error {
} else if !has {
// If the version record does not exist we think
// it is a fresh installation and we can skip all migrations.
+ currentVersion.ID = 0
currentVersion.Version = int64(_MIN_DB_VER + len(migrations))
if _, err = x.InsertOne(currentVersion); err != nil {
diff --git a/models/models.go b/models/models.go
index 4a7385f1..7ebeac9b 100644
--- a/models/models.go
+++ b/models/models.go
@@ -13,6 +13,7 @@ import (
"path"
"strings"
+ _ "github.com/denisenkom/go-mssqldb"
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
@@ -85,6 +86,8 @@ func LoadConfigs() {
setting.UseMySQL = true
case "postgres":
setting.UsePostgreSQL = true
+ case "mssql":
+ setting.UseMSSQL = true
case "tidb":
setting.UseTiDB = true
}
@@ -113,6 +116,20 @@ func parsePostgreSQLHostPort(info string) (string, string) {
return host, port
}
+func parseMSSQLHostPort(info string) (string, string) {
+ host, port := "127.0.0.1", "1433"
+ if strings.Contains(info, ":") {
+ host = strings.Split(info, ":")[0]
+ port = strings.Split(info, ":")[1]
+ } else if strings.Contains(info, ",") {
+ host = strings.Split(info, ",")[0]
+ port = strings.TrimSpace(strings.Split(info, ",")[1])
+ } else if len(info) > 0 {
+ host = info
+ }
+ return host, port
+}
+
func getEngine() (*xorm.Engine, error) {
connStr := ""
var Param string = "?"
@@ -137,6 +154,9 @@ func getEngine() (*xorm.Engine, error) {
connStr = fmt.Sprintf("postgres://%s:%s@%s:%s/%s%ssslmode=%s",
url.QueryEscape(DbCfg.User), url.QueryEscape(DbCfg.Passwd), host, port, DbCfg.Name, Param, DbCfg.SSLMode)
}
+ case "mssql":
+ host, port := parseMSSQLHostPort(DbCfg.Host)
+ connStr = fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;", host, port, DbCfg.Name, DbCfg.User, DbCfg.Passwd)
case "sqlite3":
if !EnableSQLite3 {
return nil, errors.New("This binary version does not build support for SQLite3.")
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index a1c7b427..5b8ab211 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -104,6 +104,7 @@ var (
UseSQLite3 bool
UseMySQL bool
UsePostgreSQL bool
+ UseMSSQL bool
UseTiDB bool
// Webhook settings
diff --git a/public/js/gogs.js b/public/js/gogs.js
index 6aadea59..45b11fe7 100644
--- a/public/js/gogs.js
+++ b/public/js/gogs.js
@@ -228,22 +228,21 @@ function initInstall() {
return;
}
- var mysqlDefault = '127.0.0.1:3306';
- var postgresDefault = '127.0.0.1:5432';
+ var dbDefaults = {
+ "MySQL": "127.0.0.1:3306",
+ "PostgreSQL": "127.0.0.1:5432",
+ "MSSQL": "127.0.0.1, 1433"
+ };
$('#sqlite_settings').hide();
$('#sql_settings').show();
- if (dbType === "PostgreSQL") {
- $('#pgsql_settings').show();
- if ($('#db_host').val() == mysqlDefault) {
- $('#db_host').val(postgresDefault);
- }
- } else {
- $('#pgsql_settings').hide();
- if ($('#db_host').val() == postgresDefault) {
- $('#db_host').val(mysqlDefault);
+ $('#pgsql_settings').toggle(dbType === "PostgreSQL");
+ $.each(dbDefaults, function(type, defaultHost) {
+ if ($('#db_host').val() == defaultHost) {
+ $('#db_host').val(dbDefaults[dbType]);
+ return false;
}
- }
+ });
});
// TODO: better handling of exclusive relations.
diff --git a/routers/install.go b/routers/install.go
index f4650832..dbdb2d6c 100644
--- a/routers/install.go
+++ b/routers/install.go
@@ -102,7 +102,7 @@ func InstallInit(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("install.install")
ctx.Data["PageIsInstall"] = true
- dbOpts := []string{"MySQL", "PostgreSQL"}
+ dbOpts := []string{"MySQL", "PostgreSQL", "MSSQL"}
if models.EnableSQLite3 {
dbOpts = append(dbOpts, "SQLite3")
}
@@ -122,6 +122,8 @@ func Install(ctx *context.Context) {
switch models.DbCfg.Type {
case "postgres":
ctx.Data["CurDbOption"] = "PostgreSQL"
+ case "mssql":
+ ctx.Data["CurDbOption"] = "MSSQL"
case "sqlite3":
if models.EnableSQLite3 {
ctx.Data["CurDbOption"] = "SQLite3"
@@ -191,7 +193,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
// Pass basic check, now test configuration.
// Test database setting.
- dbTypes := map[string]string{"MySQL": "mysql", "PostgreSQL": "postgres", "SQLite3": "sqlite3", "TiDB": "tidb"}
+ dbTypes := map[string]string{"MySQL": "mysql", "PostgreSQL": "postgres", "MSSQL": "mssql", "SQLite3": "sqlite3", "TiDB": "tidb"}
models.DbCfg.Type = dbTypes[form.DbType]
models.DbCfg.Host = form.DbHost
models.DbCfg.User = form.DbUser