mirror of https://github.com/1Panel-dev/1Panel
fix: 修改远程数据库列表查询规则 (#2166)
parent
ba38402a24
commit
ecc444db9f
|
@ -101,16 +101,22 @@ func (d *DatabaseRepo) WithoutByFrom(from string) DBOption {
|
||||||
|
|
||||||
func (d *DatabaseRepo) WithTypeList(dbType string) DBOption {
|
func (d *DatabaseRepo) WithTypeList(dbType string) DBOption {
|
||||||
return func(g *gorm.DB) *gorm.DB {
|
return func(g *gorm.DB) *gorm.DB {
|
||||||
types := strings.Split(dbType, ",")
|
if !strings.Contains(dbType, ",") {
|
||||||
if len(types) == 1 {
|
|
||||||
return g.Where("`type` = ?", dbType)
|
return g.Where("`type` = ?", dbType)
|
||||||
}
|
}
|
||||||
|
types := strings.Split(dbType, ",")
|
||||||
|
var (
|
||||||
|
rules []string
|
||||||
|
values []interface{}
|
||||||
|
)
|
||||||
for _, ty := range types {
|
for _, ty := range types {
|
||||||
if len(ty) != 0 {
|
if len(ty) != 0 {
|
||||||
g.Or("`type` = ?", ty)
|
rules = append(rules, "`type` = ?")
|
||||||
|
values = append(values, ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return g
|
fmt.Println(strings.Join(rules, " OR "))
|
||||||
|
return g.Where(strings.Join(rules, " OR "), values...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -486,7 +486,7 @@ var EncryptHostPassword = &gormigrate.Migration{
|
||||||
var AddRemoteDB = &gormigrate.Migration{
|
var AddRemoteDB = &gormigrate.Migration{
|
||||||
ID: "20230724-add-remote-db",
|
ID: "20230724-add-remote-db",
|
||||||
Migrate: func(tx *gorm.DB) error {
|
Migrate: func(tx *gorm.DB) error {
|
||||||
if err := tx.AutoMigrate(&model.DatabaseMysql{}); err != nil {
|
if err := tx.AutoMigrate(&model.Database{}, &model.DatabaseMysql{}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
|
|
Loading…
Reference in New Issue