Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
377b6721
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
大约 1 年 前同步成功
通知
337
Star
18155
Fork
5506
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
377b6721
编写于
6月 17, 2021
作者:
Mr.奇淼(
提交者:
GitHub
6月 17, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #527 from songzhibin97/gva_gormv2_dev
perf:优化初始化流程
上级
00b85667
ff67f055
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
13 addition
and
23 deletion
+13
-23
server/api/v1/sys_initdb.go
server/api/v1/sys_initdb.go
+2
-1
server/service/sys_initdb.go
server/service/sys_initdb.go
+11
-22
未找到文件。
server/api/v1/sys_initdb.go
浏览文件 @
377b6721
...
...
@@ -5,6 +5,7 @@ import (
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"go.uber.org/zap"
"github.com/gin-gonic/gin"
...
...
@@ -30,7 +31,7 @@ func InitDB(c *gin.Context) {
}
if
err
:=
service
.
InitDB
(
dbInfo
);
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
"自动创建数据库失败!"
,
zap
.
Any
(
"err"
,
err
))
response
.
FailWithMessage
(
"自动创建数据库失败,请查看后台日志"
,
c
)
response
.
FailWithMessage
(
"自动创建数据库失败,请查看后台日志
,检查后在进行初始化
"
,
c
)
return
}
response
.
OkWithData
(
"自动创建数据库成功"
,
c
)
...
...
server/service/sys_initdb.go
浏览文件 @
377b6721
...
...
@@ -9,10 +9,11 @@ import (
"gin-vue-admin/model/request"
"gin-vue-admin/source"
"gin-vue-admin/utils"
"path/filepath"
"github.com/spf13/viper"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"path/filepath"
)
//@author: [songzhibin97](https://github.com/songzhibin97)
...
...
@@ -71,13 +72,6 @@ func initDB(InitDBFunctions ...model.InitDBFunc) (err error) {
//@return: error
func
InitDB
(
conf
request
.
InitDB
)
error
{
BaseMysql
:=
config
.
Mysql
{
Path
:
""
,
Dbname
:
""
,
Username
:
""
,
Password
:
""
,
Config
:
"charset=utf8mb4&parseTime=True&loc=Local"
,
}
if
conf
.
Host
==
""
{
conf
.
Host
=
"127.0.0.1"
...
...
@@ -100,15 +94,11 @@ func InitDB(conf request.InitDB) error {
Config
:
"charset=utf8mb4&parseTime=True&loc=Local"
,
}
if
err
:=
writeConfig
(
global
.
GVA_VP
,
MysqlConfig
);
err
!=
nil
{
return
err
}
m
:=
global
.
GVA_CONFIG
.
Mysql
if
m
.
Dbname
==
""
{
if
MysqlConfig
.
Dbname
==
""
{
return
nil
}
linkDns
:=
m
.
Username
+
":"
+
m
.
Password
+
"@tcp("
+
m
.
Path
+
")/"
+
m
.
Dbname
+
"?"
+
m
.
Config
linkDns
:=
MysqlConfig
.
Username
+
":"
+
MysqlConfig
.
Password
+
"@tcp("
+
MysqlConfig
.
Path
+
")/"
+
MysqlConfig
.
Dbname
+
"?"
+
MysqlConfig
.
Config
mysqlConfig
:=
mysql
.
Config
{
DSN
:
linkDns
,
// DSN data source name
DefaultStringSize
:
191
,
// string 类型字段的默认长度
...
...
@@ -118,15 +108,11 @@ func InitDB(conf request.InitDB) error {
SkipInitializeWithVersion
:
false
,
// 根据版本自动配置
}
if
db
,
err
:=
gorm
.
Open
(
mysql
.
New
(
mysqlConfig
),
&
gorm
.
Config
{
DisableForeignKeyConstraintWhenMigrating
:
true
});
err
!=
nil
{
//global.GVA_LOG.Error("MySQL启动异常!", zap.Any("err", err))
//os.Exit(0)
//return nil
_
=
writeConfig
(
global
.
GVA_VP
,
BaseMysql
)
return
nil
}
else
{
sqlDB
,
_
:=
db
.
DB
()
sqlDB
.
SetMaxIdleConns
(
m
.
MaxIdleConns
)
sqlDB
.
SetMaxOpenConns
(
m
.
MaxOpenConns
)
sqlDB
.
SetMaxIdleConns
(
MysqlConfig
.
MaxIdleConns
)
sqlDB
.
SetMaxOpenConns
(
MysqlConfig
.
MaxOpenConns
)
global
.
GVA_DB
=
db
}
...
...
@@ -147,7 +133,7 @@ func InitDB(conf request.InitDB) error {
model
.
SysOperationRecord
{},
)
if
err
!=
nil
{
_
=
writeConfig
(
global
.
GVA_VP
,
BaseMysql
)
global
.
GVA_DB
=
nil
return
err
}
err
=
initDB
(
...
...
@@ -163,7 +149,10 @@ func InitDB(conf request.InitDB) error {
source
.
File
,
source
.
BaseMenu
)
if
err
!=
nil
{
_
=
writeConfig
(
global
.
GVA_VP
,
BaseMysql
)
global
.
GVA_DB
=
nil
return
err
}
if
err
=
writeConfig
(
global
.
GVA_VP
,
MysqlConfig
);
err
!=
nil
{
return
err
}
global
.
GVA_CONFIG
.
AutoCode
.
Root
,
_
=
filepath
.
Abs
(
".."
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录