diff options
author | btrepp <beautrepp@gmail.com> | 2016-12-24 09:37:35 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2016-12-24 09:37:35 +0800 |
commit | 25b5ffb6af390eac8d4a76c134379fd1ae88a423 (patch) | |
tree | e085f3f3af71ad81559ba8efeba05caceaa69fd2 /models | |
parent | f2ff0ee846e8ef42e2f7ba960e86bd8e397f007f (diff) | |
download | gitea-25b5ffb6af390eac8d4a76c134379fd1ae88a423.tar.gz gitea-25b5ffb6af390eac8d4a76c134379fd1ae88a423.zip |
Enables mssql support (#383)
* Enables mssql support
Port of dlobs work in gogs.
Enables options in index.js
Enables MSSQL as a database option in go.
Sets ID to 0 on initial migration. Required for
MSSQL insert statements.
Signed-off-by: Beau Trepp <beautrepp@gmail.com>
* Vendors in denisenkom/go-mssqldb
Includes golang.org/x/crypto/md4
as this is required by go-msssqldb
Signed-off-by: Beau Trepp <beautrepp@gmail.com>
Diffstat (limited to 'models')
-rw-r--r-- | models/migrations/migrations.go | 1 | ||||
-rw-r--r-- | models/models.go | 22 |
2 files changed, 23 insertions, 0 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 2d5aba7546..6393747b0e 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -93,6 +93,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(minDBVersion + len(migrations)) if _, err = x.InsertOne(currentVersion); err != nil { diff --git a/models/models.go b/models/models.go index 56306d61f5..c9858952b5 100644 --- a/models/models.go +++ b/models/models.go @@ -21,6 +21,9 @@ import ( // Needed for the Postgresql driver _ "github.com/lib/pq" + // Needed for the MSSSQL driver + _ "github.com/denisenkom/go-mssqldb" + "code.gitea.io/gitea/models/migrations" "code.gitea.io/gitea/modules/setting" ) @@ -97,6 +100,8 @@ func LoadConfigs() { setting.UsePostgreSQL = true case "tidb": setting.UseTiDB = true + case "mssql": + setting.UseMSSQL = true } DbCfg.Host = sec.Key("HOST").String() DbCfg.Name = sec.Key("NAME").String() @@ -123,6 +128,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 = "?" @@ -147,6 +166,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") |