From 149d44dbbe1f678665e9cab1e83d968435f75adc Mon Sep 17 00:00:00 2001
From: ssongliu <73214554+ssongliu@users.noreply.github.com>
Date: Fri, 1 Sep 2023 12:28:12 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=9C=E7=A8=8B=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E5=BA=93=E6=94=AF=E6=8C=81=E6=B7=BB=E5=8A=A0=20mariadb=20(#213?=
=?UTF-8?q?9)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
backend/app/dto/database.go | 3 +-
backend/app/repo/database.go | 24 +++++----
backend/app/service/app_install.go | 2 +-
backend/app/service/database.go | 11 +----
backend/utils/mysql/client/local.go | 2 +-
backend/utils/mysql/client/remote.go | 2 +-
frontend/src/lang/modules/en.ts | 2 +-
frontend/src/lang/modules/tw.ts | 2 +-
frontend/src/lang/modules/zh.ts | 2 +-
frontend/src/views/database/mysql/index.vue | 2 +-
.../src/views/database/mysql/remote/index.vue | 2 +-
.../database/mysql/remote/operate/index.vue | 49 +++++++++++--------
12 files changed, 55 insertions(+), 48 deletions(-)
diff --git a/backend/app/dto/database.go b/backend/app/dto/database.go
index 6317590fa..6406eb5f0 100644
--- a/backend/app/dto/database.go
+++ b/backend/app/dto/database.go
@@ -244,6 +244,7 @@ type DatabaseInfo struct {
CreatedAt time.Time `json:"createdAt"`
Name string `json:"name" validate:"max=256"`
From string `json:"from"`
+ Type string `json:"type"`
Version string `json:"version"`
Address string `json:"address"`
Port uint `json:"port"`
@@ -263,7 +264,7 @@ type DatabaseOption struct {
type DatabaseCreate struct {
Name string `json:"name" validate:"required,max=256"`
- Type string `json:"type" validate:"required,oneof=mysql"`
+ Type string `json:"type" validate:"required"`
From string `json:"from" validate:"required,oneof=local remote"`
Version string `json:"version" validate:"required"`
Address string `json:"address"`
diff --git a/backend/app/repo/database.go b/backend/app/repo/database.go
index a69f8e59c..f6a4adec9 100644
--- a/backend/app/repo/database.go
+++ b/backend/app/repo/database.go
@@ -2,6 +2,8 @@ package repo
import (
"context"
+ "strings"
+
"github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm"
@@ -18,9 +20,8 @@ type IDatabaseRepo interface {
Get(opts ...DBOption) (model.Database, error)
WithByFrom(from string) DBOption
WithoutByFrom(from string) DBOption
- WithByMysqlList() DBOption
WithAppInstallID(appInstallID uint) DBOption
- WithType(dbType string) DBOption
+ WithTypeList(dbType string) DBOption
}
func NewIDatabaseRepo() IDatabaseRepo {
@@ -59,12 +60,6 @@ func (d *DatabaseRepo) GetList(opts ...DBOption) ([]model.Database, error) {
return databases, err
}
-func (d *DatabaseRepo) WithByMysqlList() DBOption {
- return func(g *gorm.DB) *gorm.DB {
- return g.Where("type = ? OR type = ?", "mysql", "mariadb")
- }
-}
-
func (d *DatabaseRepo) WithByFrom(from string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("`from` = ?", from)
@@ -77,9 +72,18 @@ func (d *DatabaseRepo) WithoutByFrom(from string) DBOption {
}
}
-func (d *DatabaseRepo) WithType(dbType string) DBOption {
+func (d *DatabaseRepo) WithTypeList(dbType string) DBOption {
return func(g *gorm.DB) *gorm.DB {
- return g.Where("`type` = ?", dbType)
+ types := strings.Split(dbType, ",")
+ if len(types) == 1 {
+ return g.Where("`type` = ?", dbType)
+ }
+ for _, ty := range types {
+ if len(ty) != 0 {
+ g.Or("`type` = ?", ty)
+ }
+ }
+ return g
}
}
diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go
index be94b6a1c..b75ce806c 100644
--- a/backend/app/service/app_install.go
+++ b/backend/app/service/app_install.go
@@ -428,7 +428,7 @@ func (a *AppInstallService) SyncAll(systemInit bool) error {
func (a *AppInstallService) GetServices(key string) ([]response.AppService, error) {
var res []response.AppService
if DatabaseKeys[key] {
- dbs, _ := databaseRepo.GetList(databaseRepo.WithByFrom("local"), databaseRepo.WithType(key))
+ dbs, _ := databaseRepo.GetList(databaseRepo.WithByFrom("local"), commonRepo.WithByType(key))
if len(dbs) == 0 {
return res, nil
}
diff --git a/backend/app/service/database.go b/backend/app/service/database.go
index 0aab85c66..a9d3f201a 100644
--- a/backend/app/service/database.go
+++ b/backend/app/service/database.go
@@ -4,7 +4,6 @@ import (
"context"
"github.com/1Panel-dev/1Panel/backend/app/dto"
- "github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/utils/mysql"
"github.com/1Panel-dev/1Panel/backend/utils/mysql/client"
@@ -30,7 +29,7 @@ func NewIDatabaseService() IDatabaseService {
func (u *DatabaseService) SearchWithPage(search dto.DatabaseSearch) (int64, interface{}, error) {
total, dbs, err := databaseRepo.Page(search.Page, search.PageSize,
- commonRepo.WithByType(search.Type),
+ databaseRepo.WithTypeList(search.Type),
commonRepo.WithLikeName(search.Info),
databaseRepo.WithoutByFrom("local"),
)
@@ -58,13 +57,7 @@ func (u *DatabaseService) Get(name string) (dto.DatabaseInfo, error) {
}
func (u *DatabaseService) List(dbType string) ([]dto.DatabaseOption, error) {
- var opts []repo.DBOption
- if dbType == "mysql" {
- opts = append(opts, databaseRepo.WithByMysqlList())
- } else {
- opts = append(opts, commonRepo.WithByType(dbType))
- }
- dbs, err := databaseRepo.GetList(opts...)
+ dbs, err := databaseRepo.GetList(databaseRepo.WithTypeList(dbType))
var datas []dto.DatabaseOption
for _, db := range dbs {
var item dto.DatabaseOption
diff --git a/backend/utils/mysql/client/local.go b/backend/utils/mysql/client/local.go
index d1941f971..b944fee7f 100644
--- a/backend/utils/mysql/client/local.go
+++ b/backend/utils/mysql/client/local.go
@@ -147,7 +147,7 @@ func (r *Local) ChangePassword(info PasswordChangeInfo) error {
for _, user := range userlist {
passwordChangeSql := fmt.Sprintf("set password for %s = password('%s')", user, info.Password)
if !strings.HasPrefix(info.Version, "5.7") && !strings.HasPrefix(info.Version, "5.6") {
- passwordChangeSql = fmt.Sprintf("alter user %s identified by '%s';", user, info.Password)
+ passwordChangeSql = fmt.Sprintf("ALTER USER %s IDENTIFIED BY '%s';", user, info.Password)
}
if err := r.ExecSQL(passwordChangeSql, info.Timeout); err != nil {
return err
diff --git a/backend/utils/mysql/client/remote.go b/backend/utils/mysql/client/remote.go
index 7fbb2eb1a..5b8169053 100644
--- a/backend/utils/mysql/client/remote.go
+++ b/backend/utils/mysql/client/remote.go
@@ -152,7 +152,7 @@ func (r *Remote) ChangePassword(info PasswordChangeInfo) error {
for _, user := range userlist {
passwordChangeSql := fmt.Sprintf("set password for %s = password('%s')", user, info.Password)
if !strings.HasPrefix(info.Version, "5.7") && !strings.HasPrefix(info.Version, "5.6") {
- passwordChangeSql = fmt.Sprintf("ALTER USER %s IDENTIFIED WITH mysql_native_password BY '%s';", user, info.Password)
+ passwordChangeSql = fmt.Sprintf("ALTER USER %s IDENTIFIED BY '%s';", user, info.Password)
}
if err := r.ExecSQL(passwordChangeSql, info.Timeout); err != nil {
return err
diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts
index 7114bb66c..8082f46c8 100644
--- a/frontend/src/lang/modules/en.ts
+++ b/frontend/src/lang/modules/en.ts
@@ -354,7 +354,7 @@ const message = {
localDB: 'Local DB',
address: 'DB address',
version: 'DB version',
- versionHelper: 'Currently, only versions 5.6, 5.7, and 8.0 are supported',
+ versionHelper: 'Currently, only versions {0} are supported',
userHelper: 'The root user or a database user with root privileges can access the remote database.',
selectFile: 'Select file',
diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts
index bd26e15c6..a09350df4 100644
--- a/frontend/src/lang/modules/tw.ts
+++ b/frontend/src/lang/modules/tw.ts
@@ -346,7 +346,7 @@ const message = {
localDB: '本地數據庫',
address: '數據庫地址',
version: '數據庫版本',
- versionHelper: '當前僅支持 5.6 5.7 8.0 三個版本',
+ versionHelper: '當前僅支持 {0} 三個版本',
userHelper: 'root 用戶或者擁有 root 權限的數據庫用戶',
selectFile: '選擇文件',
diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts
index 7dacdc308..4ec338785 100644
--- a/frontend/src/lang/modules/zh.ts
+++ b/frontend/src/lang/modules/zh.ts
@@ -346,7 +346,7 @@ const message = {
localDB: '本地数据库',
address: '数据库地址',
version: '数据库版本',
- versionHelper: '当前仅支持 5.6 5.7 8.0 三个版本',
+ versionHelper: '当前仅支持 {0} 版本',
userHelper: 'root 用户或者拥有 root 权限的数据库用户',
selectFile: '选择文件',
diff --git a/frontend/src/views/database/mysql/index.vue b/frontend/src/views/database/mysql/index.vue
index 7bd0d548c..c0427de33 100644
--- a/frontend/src/views/database/mysql/index.vue
+++ b/frontend/src/views/database/mysql/index.vue
@@ -386,7 +386,7 @@ const checkExist = (data: App.CheckInstalled) => {
};
const loadDBOptions = async () => {
- const res = await listDatabases('mysql');
+ const res = await listDatabases('mysql,mariadb');
let datas = res.data || [];
dbOptionsLocal.value = [];
dbOptionsRemote.value = [];
diff --git a/frontend/src/views/database/mysql/remote/index.vue b/frontend/src/views/database/mysql/remote/index.vue
index 9e47c42a1..6720d877b 100644
--- a/frontend/src/views/database/mysql/remote/index.vue
+++ b/frontend/src/views/database/mysql/remote/index.vue
@@ -121,7 +121,7 @@ const search = async (column?: any) => {
page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize,
info: searchName.value,
- type: 'mysql',
+ type: 'mysql,mariadb',
orderBy: paginationConfig.orderBy,
order: paginationConfig.order,
};
diff --git a/frontend/src/views/database/mysql/remote/operate/index.vue b/frontend/src/views/database/mysql/remote/operate/index.vue
index 18d37599f..8c4c244e0 100644
--- a/frontend/src/views/database/mysql/remote/operate/index.vue
+++ b/frontend/src/views/database/mysql/remote/operate/index.vue
@@ -19,13 +19,29 @@
/>
{{ dialogData.rowData!.name }}
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
- {{ $t('database.versionHelper') }}
+
+ {{ $t('database.versionHelper', ['5.6 5.7 8.x']) }}
+
+
+ {{ $t('database.versionHelper', ['10.x']) }}
+
@@ -112,26 +128,19 @@ const rules = reactive({
type FormInstance = InstanceType;
const formRef = ref();
+const changeType = () => {
+ dialogData.value.rowData.version = dialogData.value.rowData.type === 'mysql' ? '5.6' : '10.x';
+ isOK.value = false;
+};
+
const onSubmit = async (formEl: FormInstance | undefined, operation: string) => {
if (!formEl) return;
formEl.validate(async (valid) => {
if (!valid) return;
- let param = {
- id: dialogData.value.rowData.id,
- name: dialogData.value.rowData.name,
- type: 'mysql',
- version: dialogData.value.rowData.version,
- from: 'remote',
- address: dialogData.value.rowData.address,
- port: dialogData.value.rowData.port,
- username: dialogData.value.rowData.username,
- password: dialogData.value.rowData.password,
- description: dialogData.value.rowData.description,
- };
+ dialogData.value.rowData.from = 'remote';
loading.value = true;
-
if (operation === 'check') {
- await checkDatabase(param)
+ await checkDatabase(dialogData.value.rowData)
.then((res) => {
loading.value = false;
if (res.data) {
@@ -148,7 +157,7 @@ const onSubmit = async (formEl: FormInstance | undefined, operation: string) =>
}
if (operation === 'create') {
- await addDatabase(param)
+ await addDatabase(dialogData.value.rowData)
.then(() => {
loading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
@@ -160,7 +169,7 @@ const onSubmit = async (formEl: FormInstance | undefined, operation: string) =>
});
}
if (operation === 'edit') {
- await editDatabase(param)
+ await editDatabase(dialogData.value.rowData)
.then(() => {
loading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));