feat✨: 添加sqlserver支持

This commit is contained in:
wenjianzhang committed 2022-02-08 18:41:09 +08:00
1 parent 02b62a288d
commit d02b52f383
8 files changed
+366 -38

No files matched your search

+2 -2
View File
@@ -46,7 +46,7 @@ func (e *Migration) Migrate() {
var err error
var count int64
for _, v := range versions {
err = e.db.Debug().Table("sys_migration").Where("version = ?", v).Count(&count).Error
err = e.db.Table("sys_migration").Where("version = ?", v).Count(&count).Error
if err != nil {
log.Fatalln(err)
}
@@ -55,7 +55,7 @@ func (e *Migration) Migrate() {
count = 0
continue
}
err = (e.version[v])(e.db.Debug(), strconv.Itoa(v))
err = (e.version[v])(e.db, strconv.Itoa(v))
if err != nil {
log.Fatalln(err)
}
+2 -24
View File
@@ -1,7 +1,6 @@
package models
import (
"errors"
"fmt"
"go-admin/common/global"
"gorm.io/gorm"
@@ -13,40 +12,19 @@ import (
func InitDb(db *gorm.DB) (err error) {
filePath := "config/db.sql"
if global.Driver == "postgres" {
err = ExecSql(db, filePath)
if err != nil {
return err
}
filePath = "config/pg.sql"
err = ExecSql(db, filePath)
if err != nil {
return err
}
} else if global.Driver == "mysql" {
filePath = "config/db-begin-mysql.sql"
err = ExecSql(db, filePath)
if err != nil {
return err
}
filePath = "config/db.sql"
err = ExecSql(db, filePath)
if err != nil {
return err
}
filePath = "config/db-end-mysql.sql"
err = ExecSql(db, filePath)
if err != nil {
return err
}
} else if global.Driver == "sqlite3" {
err = ExecSql(db, filePath)
if err != nil {
return err
}
} else {
return errors.New("database type is not supported")
err = ExecSql(db, filePath)
}
return nil
return err
}
func ExecSql(db *gorm.DB, filePath string) error {
+4 -4
View File
@@ -11,13 +11,13 @@ type SysUser struct {
Password string `json:"-" gorm:"type:varchar(128);comment:密码"`
NickName string `json:"nickName" gorm:"type:varchar(128);comment:昵称"`
Phone string `json:"phone" gorm:"type:varchar(11);comment:手机号"`
RoleId int `json:"roleId" gorm:"type:bigint(20);comment:角色ID"`
RoleId int `json:"roleId" gorm:"type:bigint;comment:角色ID"`
Salt string `json:"-" gorm:"type:varchar(255);comment:加盐"`
Avatar string `json:"avatar" gorm:"type:varchar(255);comment:头像"`
Sex string `json:"sex" gorm:"type:varchar(255);comment:性别"`
Email string `json:"email" gorm:"type:varchar(128);comment:邮箱"`
DeptId int `json:"deptId" gorm:"type:bigint(20);comment:部门"`
PostId int `json:"postId" gorm:"type:bigint(20);comment:岗位"`
DeptId int `json:"deptId" gorm:"type:bigint;comment:部门"`
PostId int `json:"postId" gorm:"type:bigint;comment:岗位"`
Remark string `json:"remark" gorm:"type:varchar(255);comment:备注"`
Status string `json:"status" gorm:"type:varchar(4);comment:状态"`
ControlBy
@@ -45,4 +45,4 @@ func (e *SysUser) Encrypt() (err error) {
func (e *SysUser) BeforeCreate(_ *gorm.DB) error {
return e.Encrypt()
}
}