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:
parent
d626b2f4bd
commit
040a0663c6
@ -17,6 +17,7 @@ type IAppRepo interface {
|
|||||||
OrderByRecommend() DBOption
|
OrderByRecommend() DBOption
|
||||||
GetRecommend() DBOption
|
GetRecommend() DBOption
|
||||||
WithResource(resource string) DBOption
|
WithResource(resource string) DBOption
|
||||||
|
WithLikeName(name string) DBOption
|
||||||
Page(page, size int, opts ...DBOption) (int64, []model.App, error)
|
Page(page, size int, opts ...DBOption) (int64, []model.App, error)
|
||||||
GetFirst(opts ...DBOption) (model.App, error)
|
GetFirst(opts ...DBOption) (model.App, error)
|
||||||
GetBy(opts ...DBOption) ([]model.App, error)
|
GetBy(opts ...DBOption) ([]model.App, error)
|
||||||
@ -31,6 +32,15 @@ func NewIAppRepo() IAppRepo {
|
|||||||
return &AppRepo{}
|
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 {
|
func (a AppRepo) WithKey(key string) DBOption {
|
||||||
return func(db *gorm.DB) *gorm.DB {
|
return func(db *gorm.DB) *gorm.DB {
|
||||||
return db.Where("key = ?", key)
|
return db.Where("key = ?", key)
|
||||||
|
@ -92,7 +92,7 @@ func (c *CommonRepo) WithLikeName(name string) DBOption {
|
|||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
return g
|
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+"%")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) {
|
|||||||
var opts []repo.DBOption
|
var opts []repo.DBOption
|
||||||
opts = append(opts, appRepo.OrderByRecommend())
|
opts = append(opts, appRepo.OrderByRecommend())
|
||||||
if req.Name != "" {
|
if req.Name != "" {
|
||||||
opts = append(opts, commonRepo.WithLikeName(req.Name))
|
opts = append(opts, appRepo.WithLikeName(req.Name))
|
||||||
}
|
}
|
||||||
if req.Type != "" {
|
if req.Type != "" {
|
||||||
opts = append(opts, appRepo.WithType(req.Type))
|
opts = append(opts, appRepo.WithType(req.Type))
|
||||||
|
@ -432,6 +432,9 @@ func (a *AppInstallService) SyncAll(systemInit bool) error {
|
|||||||
func (a *AppInstallService) GetServices(key string) ([]response.AppService, error) {
|
func (a *AppInstallService) GetServices(key string) ([]response.AppService, error) {
|
||||||
var res []response.AppService
|
var res []response.AppService
|
||||||
if DatabaseKeys[key] > 0 {
|
if DatabaseKeys[key] > 0 {
|
||||||
|
if key == constant.AppPostgres {
|
||||||
|
key = constant.AppPostgresql
|
||||||
|
}
|
||||||
dbs, _ := databaseRepo.GetList(commonRepo.WithByType(key))
|
dbs, _ := databaseRepo.GetList(commonRepo.WithByType(key))
|
||||||
if len(dbs) == 0 {
|
if len(dbs) == 0 {
|
||||||
return res, nil
|
return res, nil
|
||||||
|
@ -110,12 +110,13 @@ func checkPortExist(port int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var DatabaseKeys = map[string]uint{
|
var DatabaseKeys = map[string]uint{
|
||||||
"mysql": 3306,
|
constant.AppMysql: 3306,
|
||||||
"mariadb": 3306,
|
constant.AppMariaDB: 3306,
|
||||||
"postgresql": 5432,
|
constant.AppPostgresql: 5432,
|
||||||
"mongodb": 27017,
|
constant.AppPostgres: 5432,
|
||||||
"redis": 6379,
|
constant.AppMongodb: 27017,
|
||||||
"memcached": 11211,
|
constant.AppRedis: 6379,
|
||||||
|
constant.AppMemcached: 11211,
|
||||||
}
|
}
|
||||||
|
|
||||||
var ToolKeys = map[string]uint{
|
var ToolKeys = map[string]uint{
|
||||||
@ -154,7 +155,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch app.Key {
|
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, ok := params["PANEL_DB_ROOT_PASSWORD"]; ok {
|
||||||
if password != "" {
|
if password != "" {
|
||||||
database.Password = password.(string)
|
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, ok := params["PANEL_REDIS_ROOT_PASSWORD"]; ok {
|
||||||
if password != "" {
|
if password != "" {
|
||||||
authParam := dto.RedisAuthParam{
|
authParam := dto.RedisAuthParam{
|
||||||
@ -234,7 +235,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
|
|||||||
var resourceId uint
|
var resourceId uint
|
||||||
if dbConfig.DbName != "" && dbConfig.DbUser != "" && dbConfig.Password != "" {
|
if dbConfig.DbName != "" && dbConfig.DbUser != "" && dbConfig.Password != "" {
|
||||||
switch database.Type {
|
switch database.Type {
|
||||||
case constant.AppPostgresql:
|
case constant.AppPostgresql, constant.AppPostgres:
|
||||||
iPostgresqlRepo := repo.NewIPostgresqlRepo()
|
iPostgresqlRepo := repo.NewIPostgresqlRepo()
|
||||||
oldPostgresqlDb, _ := iPostgresqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iPostgresqlRepo.WithByFrom(constant.ResourceLocal))
|
oldPostgresqlDb, _ := iPostgresqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iPostgresqlRepo.WithByFrom(constant.ResourceLocal))
|
||||||
resourceId = oldPostgresqlDb.ID
|
resourceId = oldPostgresqlDb.ID
|
||||||
@ -256,7 +257,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
|
|||||||
}
|
}
|
||||||
resourceId = pgdb.ID
|
resourceId = pgdb.ID
|
||||||
}
|
}
|
||||||
case "mysql", "mariadb":
|
case constant.AppMysql, constant.AppMariaDB:
|
||||||
iMysqlRepo := repo.NewIMysqlRepo()
|
iMysqlRepo := repo.NewIMysqlRepo()
|
||||||
oldMysqlDb, _ := iMysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iMysqlRepo.WithByFrom(constant.ResourceLocal))
|
oldMysqlDb, _ := iMysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iMysqlRepo.WithByFrom(constant.ResourceLocal))
|
||||||
resourceId = oldMysqlDb.ID
|
resourceId = oldMysqlDb.ID
|
||||||
|
@ -19,11 +19,14 @@ const (
|
|||||||
AppNormal = "Normal"
|
AppNormal = "Normal"
|
||||||
AppTakeDown = "TakeDown"
|
AppTakeDown = "TakeDown"
|
||||||
|
|
||||||
AppOpenresty = "openresty"
|
AppOpenresty = "openresty"
|
||||||
AppMysql = "mysql"
|
AppMysql = "mysql"
|
||||||
AppMariaDB = "mariadb"
|
AppMariaDB = "mariadb"
|
||||||
AppPostgresql = "postgresql"
|
AppPostgresql = "postgresql"
|
||||||
AppRedis = "redis"
|
AppRedis = "redis"
|
||||||
|
AppPostgres = "postgres"
|
||||||
|
AppMongodb = "mongodb"
|
||||||
|
AppMemcached = "memcached"
|
||||||
|
|
||||||
AppResourceLocal = "local"
|
AppResourceLocal = "local"
|
||||||
AppResourceRemote = "remote"
|
AppResourceRemote = "remote"
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
</el-button>
|
</el-button>
|
||||||
<el-divider v-if="data.app === 'OpenResty'" direction="vertical" />
|
<el-divider v-if="data.app === 'OpenResty'" direction="vertical" />
|
||||||
<el-button
|
<el-button
|
||||||
|
v-if="data.app === 'OpenResty'"
|
||||||
type="primary"
|
type="primary"
|
||||||
@click="clear"
|
@click="clear"
|
||||||
link
|
link
|
||||||
|
@ -414,7 +414,7 @@ const appInstalles = ref<App.AppInstalled[]>([]);
|
|||||||
const appReq = reactive({
|
const appReq = reactive({
|
||||||
type: 'website',
|
type: 'website',
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: 20,
|
pageSize: 100,
|
||||||
});
|
});
|
||||||
const apps = ref<App.App[]>([]);
|
const apps = ref<App.App[]>([]);
|
||||||
const appVersions = ref<string[]>([]);
|
const appVersions = ref<string[]>([]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user