diff --git a/backend/app/service/database.go b/backend/app/service/database.go index 8dd711e80..010d73fab 100644 --- a/backend/app/service/database.go +++ b/backend/app/service/database.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/1Panel-dev/1Panel/backend/app/dto" + "github.com/1Panel-dev/1Panel/backend/buserr" "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/utils/encrypt" "github.com/1Panel-dev/1Panel/backend/utils/mysql" @@ -89,6 +90,9 @@ func (u *DatabaseService) CheckDatabase(req dto.DatabaseCreate) bool { func (u *DatabaseService) Create(req dto.DatabaseCreate) error { db, _ := databaseRepo.Get(commonRepo.WithByName(req.Name)) if db.ID != 0 { + if db.From == "local" { + return buserr.New(constant.ErrLocalExist) + } return constant.ErrRecordExist } if _, err := mysql.NewMysqlClient(client.DBInfo{ diff --git a/backend/constant/errs.go b/backend/constant/errs.go index 873a9a29c..a4f8ad22f 100644 --- a/backend/constant/errs.go +++ b/backend/constant/errs.go @@ -96,6 +96,8 @@ var ( ErrUserIsExist = "ErrUserIsExist" ErrDatabaseIsExist = "ErrDatabaseIsExist" ErrExecTimeOut = "ErrExecTimeOut" + ErrRemoteExist = "ErrRemoteExist" + ErrLocalExist = "ErrLocalExist" ) // redis diff --git a/backend/i18n/lang/en.yaml b/backend/i18n/lang/en.yaml index 0a57fa5d3..fd51b6c09 100644 --- a/backend/i18n/lang/en.yaml +++ b/backend/i18n/lang/en.yaml @@ -83,6 +83,8 @@ ErrOpenrestyPort: 'The default port of openresty is {{ .detail }}, HTTP mode can ErrUserIsExist: "The current user already exists. Please enter a new user" ErrDatabaseIsExist: "The current database already exists. Please enter a new database" ErrExecTimeOut: "SQL execution timed out, please check the database" +ErrRemoteExist: "The remote database already exists with that name, please modify it and try again" +ErrLocalExist: "The local database already exists with that name, please modify it and try again" #redis ErrTypeOfRedis: "The recovery file type does not match the current persistence mode. Modify the file type and try again" diff --git a/backend/i18n/lang/zh-Hant.yaml b/backend/i18n/lang/zh-Hant.yaml index 12ec41da1..7178715d0 100644 --- a/backend/i18n/lang/zh-Hant.yaml +++ b/backend/i18n/lang/zh-Hant.yaml @@ -83,6 +83,8 @@ ErrOpenrestyPort: 'openresty 默認端口為 {{ .detail }},無法使用 HTTP ErrUserIsExist: "當前用戶已存在,請重新輸入" ErrDatabaseIsExist: "當前資料庫已存在,請重新輸入" ErrExecTimeOut: "SQL 執行超時,請檢查數據庫" +ErrRemoteExist: "遠程數據庫已存在該名稱,請修改後重試" +ErrLocalExist: "本地數據庫已存在該名稱,請修改後重試" #redis ErrTypeOfRedis: "恢復文件類型與當前持久化方式不符,請修改後重試" diff --git a/backend/i18n/lang/zh.yaml b/backend/i18n/lang/zh.yaml index 7d32a11f8..e9aefaf06 100644 --- a/backend/i18n/lang/zh.yaml +++ b/backend/i18n/lang/zh.yaml @@ -83,6 +83,8 @@ ErrOpenrestyPort: 'openresty 默认端口为 {{ .detail }},无法使用 HTTP ErrUserIsExist: "当前用户已存在,请重新输入" ErrDatabaseIsExist: "当前数据库已存在,请重新输入" ErrExecTimeOut: "SQL 执行超时,请检查数据库" +ErrRemoteExist: "远程数据库已存在该名称,请修改后重试" +ErrLocalExist: "本地数据库已存在该名称,请修改后重试" #redis ErrTypeOfRedis: "恢复文件类型与当前持久化方式不符,请修改后重试"