Browse Source

Merge branch 'pgsqlDevelop' of github.com:flipped-aurora/gin-vue-admin into pgsqlDevelop

main
蒋吉兆 3 years ago
parent
commit
4f6cb72393
  1. 23
      server/service/system/sys_auto_code_pgsql.go
  2. 2
      server/service/system/sys_initdb_mysql.go
  3. 4
      server/service/system/sys_initdb_pgsql.go

23
server/service/system/sys_auto_code_pgsql.go

@ -7,6 +7,7 @@ import (
"gorm.io/driver/postgres" "gorm.io/driver/postgres"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/logger" "gorm.io/gorm/logger"
"strings"
) )
var AutoCodePgsql = new(autoCodePgsql) var AutoCodePgsql = new(autoCodePgsql)
@ -60,17 +61,29 @@ func (a *autoCodePgsql) GetColumn(tableName string, dbName string) (data []respo
WHEN 'bigint' THEN WHEN 'bigint' THEN
concat_ws('', '', columns.NUMERIC_PRECISION) concat_ws('', '', columns.NUMERIC_PRECISION)
ELSE '' ELSE ''
END AS data_type_long
END AS data_type_long,
(select description.description
from pg_description description
where description.objoid = (select attribute.attrelid
from pg_attribute attribute
where attribute.attrelid =
(select oid from pg_class class where class.relname = '@table_name') and attname =columns.COLUMN_NAME )
and description.objsubid = (select attribute.attnum
from pg_attribute attribute
where attribute.attrelid =
(select oid from pg_class class where class.relname = '@table_name') and attname =columns.COLUMN_NAME )) as column_comment
FROM INFORMATION_SCHEMA.COLUMNS columns FROM INFORMATION_SCHEMA.COLUMNS columns
WHERE table_catalog = ?
and table_schema = ?
and table_name = ?
WHERE table_catalog = '@table_catalog'
and table_schema = 'public'
and table_name = '@table_name';
` `
var entities []response.Column var entities []response.Column
db, _err := gorm.Open(postgres.Open(global.GVA_CONFIG.Pgsql.LinkDsn(dbName)), &gorm.Config{Logger: logger.Default.LogMode(logger.Info)}) db, _err := gorm.Open(postgres.Open(global.GVA_CONFIG.Pgsql.LinkDsn(dbName)), &gorm.Config{Logger: logger.Default.LogMode(logger.Info)})
if _err != nil { if _err != nil {
return nil, errors.Wrapf(err, "[pgsql] 连接 数据库(%s)的表(%s)失败!", dbName, tableName) return nil, errors.Wrapf(err, "[pgsql] 连接 数据库(%s)的表(%s)失败!", dbName, tableName)
} }
err = db.Raw(sql, dbName, "public", tableName).Scan(&entities).Error
sql = strings.ReplaceAll(sql, "@table_catalog", dbName)
sql = strings.ReplaceAll(sql, "@table_name", tableName)
err = db.Raw(sql).Scan(&entities).Error
return entities, err return entities, err
} }

2
server/service/system/sys_initdb_mysql.go

@ -24,7 +24,7 @@ func (initDBService *InitDBService) writeMysqlConfig(mysql config.Mysql) error {
for k, v := range cs { for k, v := range cs {
global.GVA_VP.Set(k, v) global.GVA_VP.Set(k, v)
} }
global.GVA_VP.Set("jwt.signing-key", uuid.NewV4())
global.GVA_VP.Set("jwt.signing-key", uuid.NewV4().String())
return global.GVA_VP.WriteConfig() return global.GVA_VP.WriteConfig()
} }

4
server/service/system/sys_initdb_pgsql.go

@ -23,7 +23,7 @@ func (initDBService *InitDBService) writePgsqlConfig(pgsql config.Pgsql) error {
for k, v := range cs { for k, v := range cs {
global.GVA_VP.Set(k, v) global.GVA_VP.Set(k, v)
} }
global.GVA_VP.Set("jwt.signing-key", uuid.NewV4())
global.GVA_VP.Set("jwt.signing-key", uuid.NewV4().String())
return global.GVA_VP.WriteConfig() return global.GVA_VP.WriteConfig()
} }
@ -69,7 +69,7 @@ func (initDBService *InitDBService) initPgsqlDB(conf request.InitDB) error {
// initPgsqlData pgsql 初始化数据 // initPgsqlData pgsql 初始化数据
// Author [SliverHorn](https://github.com/SliverHorn) // Author [SliverHorn](https://github.com/SliverHorn)
func (initDBService *InitDBService) initPgsqlData() error { func (initDBService *InitDBService) initPgsqlData() error {
return model.MysqlDataInitialize(
return model.PgsqlDataInitialize(
system.Api, system.Api,
system.User, system.User,
system.Casbin, system.Casbin,

Loading…
Cancel
Save