fixed:
- pgsql 修复初始化数据失败的bug - pgsql 获取角色菜单时 报错 - SysOperationRecord longtext 改为 text
This commit is contained in:
@@ -122,9 +122,9 @@ func (authorityService *AuthorityService) GetAuthorityInfoList(info request.Page
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
db := global.GVA_DB.Model(&system.SysAuthority{})
|
||||
err = db.Where("parent_id = 0").Count(&total).Error
|
||||
err = db.Where("parent_id = ?", "0").Count(&total).Error
|
||||
var authority []system.SysAuthority
|
||||
err = db.Limit(limit).Offset(offset).Preload("DataAuthorityId").Where("parent_id = 0").Find(&authority).Error
|
||||
err = db.Limit(limit).Offset(offset).Preload("DataAuthorityId").Where("parent_id = ?", "0").Find(&authority).Error
|
||||
if len(authority) > 0 {
|
||||
for k := range authority {
|
||||
err = authorityService.findChildrenAuthority(&authority[k])
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
adapter "github.com/casbin/gorm-adapter/v3"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/example"
|
||||
@@ -26,7 +28,7 @@ func (initDBService *InitDBService) InitDB(conf request.InitDB) error {
|
||||
}
|
||||
|
||||
// initTables 初始化表
|
||||
// Author SliverHorn
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func (initDBService *InitDBService) initTables() error {
|
||||
return global.GVA_DB.AutoMigrate(
|
||||
system.SysApi{},
|
||||
@@ -49,3 +51,25 @@ func (initDBService *InitDBService) initTables() error {
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
// createDatabase 创建数据库(mysql)
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
// Author: [songzhibin97](https://github.com/songzhibin97)
|
||||
|
||||
func (initDBService *InitDBService) createDatabase(dsn string, driver string, createSql string) error {
|
||||
db, err := sql.Open(driver, dsn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func(db *sql.DB) {
|
||||
err = db.Close()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}(db)
|
||||
if err = db.Ping(); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = db.Exec(createSql)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/config"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
@@ -29,27 +28,6 @@ func (initDBService *InitDBService) writeMysqlConfig(mysql config.Mysql) error {
|
||||
return global.GVA_VP.WriteConfig()
|
||||
}
|
||||
|
||||
// createDatabase 创建数据库(mysql)
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
// Author: [songzhibin97](https://github.com/songzhibin97)
|
||||
func (initDBService *InitDBService) createDatabase(dsn string, driver string, createSql string) error {
|
||||
db, err := sql.Open(driver, dsn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func(db *sql.DB) {
|
||||
err = db.Close()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}(db)
|
||||
if err = db.Ping(); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = db.Exec(createSql)
|
||||
return err
|
||||
}
|
||||
|
||||
// initMsqlDB 创建数据库并初始化 mysql
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
@@ -110,6 +88,6 @@ func (initDBService *InitDBService) initMysqlData() error {
|
||||
system.AuthoritiesMenus,
|
||||
system.DictionaryDetail,
|
||||
system.ViewAuthorityMenuMysql,
|
||||
example.File,
|
||||
example.FileMysql,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/config"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
model "github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
@@ -9,7 +8,6 @@ import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/source/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/source/system"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
"github.com/jackc/pgx/v4"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
@@ -19,6 +17,7 @@ import (
|
||||
// writePgsqlConfig pgsql 回写配置
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func (initDBService *InitDBService) writePgsqlConfig(pgsql config.Pgsql) error {
|
||||
global.GVA_CONFIG.System.DbType = "pgsql"
|
||||
global.GVA_CONFIG.Pgsql = pgsql
|
||||
cs := utils.StructToMap(global.GVA_CONFIG)
|
||||
for k, v := range cs {
|
||||
@@ -28,27 +27,10 @@ func (initDBService *InitDBService) writePgsqlConfig(pgsql config.Pgsql) error {
|
||||
return global.GVA_VP.WriteConfig()
|
||||
}
|
||||
|
||||
// createPgsqlDatabase 根据页面传递的数据库名 创建数据库
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func (initDBService *InitDBService) createPgsqlDatabase(dsn string, dbName string) error {
|
||||
ctx := context.Background()
|
||||
_sql := "CREATE DATABASE " + dbName
|
||||
db, err := pgx.Connect(ctx, dsn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
_ = db.Close(ctx)
|
||||
}()
|
||||
if err = db.Ping(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = db.Exec(ctx, _sql)
|
||||
return err
|
||||
}
|
||||
func (initDBService *InitDBService) initPgsqlDB(conf request.InitDB) error {
|
||||
dsn := conf.PgsqlEmptyDsn()
|
||||
if err := initDBService.createPgsqlDatabase(dsn, conf.DBName); err != nil {
|
||||
createSql := "CREATE DATABASE " + conf.DBName
|
||||
if err := initDBService.createDatabase(dsn, "pgx", createSql); err != nil {
|
||||
return err
|
||||
} // 创建数据库
|
||||
|
||||
@@ -100,6 +82,6 @@ func (initDBService *InitDBService) initPgsqlData() error {
|
||||
system.DictionaryDetail,
|
||||
system.ViewAuthorityMenuPostgres,
|
||||
|
||||
example.File,
|
||||
example.FilePgsql,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user