1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

feat: 应用安装支持选择 postgres (#3504)

This commit is contained in:
zhengkunwang 2024-01-03 13:26:29 +08:00 committed by GitHub
parent d626b2f4bd
commit 040a0663c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 35 additions and 17 deletions

View File

@ -17,6 +17,7 @@ type IAppRepo interface {
OrderByRecommend() DBOption
GetRecommend() DBOption
WithResource(resource string) DBOption
WithLikeName(name string) DBOption
Page(page, size int, opts ...DBOption) (int64, []model.App, error)
GetFirst(opts ...DBOption) (model.App, error)
GetBy(opts ...DBOption) ([]model.App, error)
@ -31,6 +32,15 @@ func NewIAppRepo() IAppRepo {
return &AppRepo{}
}
func (a AppRepo) WithLikeName(name string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(name) == 0 {
return g
}
return g.Where("name like ? or short_desc_zh like ? or short_desc_en like ?", "%"+name+"%", "%"+name+"%", "%"+name+"%")
}
}
func (a AppRepo) WithKey(key string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("key = ?", key)

View File

@ -92,7 +92,7 @@ func (c *CommonRepo) WithLikeName(name string) DBOption {
if len(name) == 0 {
return g
}
return g.Where("name like ? or short_desc_zh like ? or short_desc_en like ?", "%"+name+"%", "%"+name+"%", "%"+name+"%")
return g.Where("name like ?", "%"+name+"%")
}
}

View File

@ -53,7 +53,7 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) {
var opts []repo.DBOption
opts = append(opts, appRepo.OrderByRecommend())
if req.Name != "" {
opts = append(opts, commonRepo.WithLikeName(req.Name))
opts = append(opts, appRepo.WithLikeName(req.Name))
}
if req.Type != "" {
opts = append(opts, appRepo.WithType(req.Type))

View File

@ -432,6 +432,9 @@ func (a *AppInstallService) SyncAll(systemInit bool) error {
func (a *AppInstallService) GetServices(key string) ([]response.AppService, error) {
var res []response.AppService
if DatabaseKeys[key] > 0 {
if key == constant.AppPostgres {
key = constant.AppPostgresql
}
dbs, _ := databaseRepo.GetList(commonRepo.WithByType(key))
if len(dbs) == 0 {
return res, nil

View File

@ -110,12 +110,13 @@ func checkPortExist(port int) error {
}
var DatabaseKeys = map[string]uint{
"mysql": 3306,
"mariadb": 3306,
"postgresql": 5432,
"mongodb": 27017,
"redis": 6379,
"memcached": 11211,
constant.AppMysql: 3306,
constant.AppMariaDB: 3306,
constant.AppPostgresql: 5432,
constant.AppPostgres: 5432,
constant.AppMongodb: 27017,
constant.AppRedis: 6379,
constant.AppMemcached: 11211,
}
var ToolKeys = map[string]uint{
@ -154,7 +155,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
}
switch app.Key {
case "mysql", "mariadb", constant.AppPostgresql, "mongodb":
case constant.AppMysql, constant.AppMariaDB, constant.AppPostgresql, constant.AppMongodb:
if password, ok := params["PANEL_DB_ROOT_PASSWORD"]; ok {
if password != "" {
database.Password = password.(string)
@ -176,7 +177,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
}
}
case "redis":
case constant.AppRedis:
if password, ok := params["PANEL_REDIS_ROOT_PASSWORD"]; ok {
if password != "" {
authParam := dto.RedisAuthParam{
@ -234,7 +235,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
var resourceId uint
if dbConfig.DbName != "" && dbConfig.DbUser != "" && dbConfig.Password != "" {
switch database.Type {
case constant.AppPostgresql:
case constant.AppPostgresql, constant.AppPostgres:
iPostgresqlRepo := repo.NewIPostgresqlRepo()
oldPostgresqlDb, _ := iPostgresqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iPostgresqlRepo.WithByFrom(constant.ResourceLocal))
resourceId = oldPostgresqlDb.ID
@ -256,7 +257,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
}
resourceId = pgdb.ID
}
case "mysql", "mariadb":
case constant.AppMysql, constant.AppMariaDB:
iMysqlRepo := repo.NewIMysqlRepo()
oldMysqlDb, _ := iMysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iMysqlRepo.WithByFrom(constant.ResourceLocal))
resourceId = oldMysqlDb.ID

View File

@ -19,11 +19,14 @@ const (
AppNormal = "Normal"
AppTakeDown = "TakeDown"
AppOpenresty = "openresty"
AppMysql = "mysql"
AppMariaDB = "mariadb"
AppOpenresty = "openresty"
AppMysql = "mysql"
AppMariaDB = "mariadb"
AppPostgresql = "postgresql"
AppRedis = "redis"
AppRedis = "redis"
AppPostgres = "postgres"
AppMongodb = "mongodb"
AppMemcached = "memcached"
AppResourceLocal = "local"
AppResourceRemote = "remote"

View File

@ -52,6 +52,7 @@
</el-button>
<el-divider v-if="data.app === 'OpenResty'" direction="vertical" />
<el-button
v-if="data.app === 'OpenResty'"
type="primary"
@click="clear"
link

View File

@ -414,7 +414,7 @@ const appInstalles = ref<App.AppInstalled[]>([]);
const appReq = reactive({
type: 'website',
page: 1,
pageSize: 20,
pageSize: 100,
});
const apps = ref<App.App[]>([]);
const appVersions = ref<string[]>([]);