feat: Adapt to PostgreSQL cluster (#9529)

This commit is contained in:
CityFun 2025-07-16 17:44:20 +08:00 committed by GitHub
parent 75bfc3a114
commit ef2cb1b315
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 13 additions and 6 deletions

View file

@ -473,13 +473,17 @@ func (a *AppInstallService) SyncAll(systemInit bool) error {
func (a *AppInstallService) GetServices(key string) ([]response.AppService, error) {
var res []response.AppService
if DatabaseKeys[key] > 0 {
types := []string{key}
if key == constant.AppPostgres {
key = constant.AppPostgresql
}
types := []string{key}
if key == constant.AppMysql {
switch key {
case constant.AppMysql:
types = []string{constant.AppMysql, constant.AppMysqlCluster}
case constant.AppPostgresql:
types = []string{constant.AppPostgresql, constant.AppPostgresqlCluster}
}
dbs, _ := databaseRepo.GetList(repo.WithTypes(types))
if len(dbs) == 0 {
return res, nil

View file

@ -92,7 +92,7 @@ func (u *DatabaseService) LoadItems(dbType string) ([]dto.DatabaseItem, error) {
dbs, err := databaseRepo.GetList(databaseRepo.WithTypeList(dbType))
var datas []dto.DatabaseItem
for _, db := range dbs {
if dbType == "postgresql" {
if dbType == constant.AppPostgresql || dbType == constant.AppPostgresqlCluster {
items, _ := postgresqlRepo.List(postgresqlRepo.WithByPostgresqlName(db.Name))
for _, item := range items {
var dItem dto.DatabaseItem

View file

@ -44,6 +44,8 @@ func (u *DBCommonService) LoadDatabaseFile(req dto.OperationWithNameAndType) (st
switch req.Type {
case "mysql-cluster-conf":
filePath = path.Join(global.Dir.DataDir, fmt.Sprintf("apps/mysql-cluster/%s/conf/my.cnf", req.Name))
case "postgresql-cluster-conf":
filePath = path.Join(global.Dir.DataDir, fmt.Sprintf("apps/postgresql-cluster/%s/data/postgresql.conf", req.Name))
case "mysql-conf":
filePath = path.Join(global.Dir.DataDir, fmt.Sprintf("apps/mysql/%s/conf/my.cnf", req.Name))
case "mariadb-conf":

View file

@ -28,7 +28,7 @@ type PostgresqlClient interface {
func NewPostgresqlClient(conn client.DBInfo) (PostgresqlClient, error) {
if conn.From == "local" {
connArgs := []string{"exec", conn.Address, "psql", "-t", "-U", conn.Username, "-c"}
connArgs := []string{"exec", "-e", fmt.Sprintf("PGPASSWORD=%s", conn.Password), conn.Address, "psql", "-t", "-U", conn.Username, "-c"}
return client.NewLocal(connArgs, conn.Address, conn.Username, conn.Password, conn.Database), nil
}
escapedUsername := url.QueryEscape(conn.Username)

View file

@ -11,6 +11,7 @@ type DBInfo struct {
Port uint `json:"port"`
Username string `json:"userName"`
Password string `json:"password"`
AppKey string `json:"appKey"`
Timeout uint `json:"timeout"` // second
}

View file

@ -136,7 +136,7 @@ func (r *Local) Backup(info BackupInfo) error {
}
defer outfile.Close()
global.LOG.Infof("start to pg_dump | gzip > %s.gzip", info.TargetDir+"/"+info.FileName)
cmd := exec.Command("docker", "exec", r.ContainerName, "pg_dump", "-F", "c", "-U", r.Username, "-d", info.Name)
cmd := exec.Command("docker", "exec", "-e", fmt.Sprintf("PGPASSWORD=%s", r.Password), r.ContainerName, "pg_dump", "-F", "c", "-U", r.Username, "-d", info.Name)
var stderr bytes.Buffer
cmd.Stderr = &stderr

View file

@ -445,7 +445,7 @@ const checkExist = (data: App.CheckInstalled) => {
const loadDBOptions = async () => {
try {
const res = await listDatabases('postgresql');
const res = await listDatabases('postgresql,postgresql-cluster');
let datas = res.data || [];
dbOptionsLocal.value = [];
dbOptionsRemote.value = [];