mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-30 14:56:34 +08:00
可以清理数据库节点的数据表
This commit is contained in:
56
internal/web/actions/default/db/cleanPopup.go
Normal file
56
internal/web/actions/default/db/cleanPopup.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type CleanPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CleanPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CleanPopupAction) RunGet(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
this.Data["nodeId"] = params.NodeId
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CleanPopupAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
tablesResp, err := this.RPC().DBNodeRPC().FindAllDBNodeTables(this.AdminContext(), &pb.FindAllDBNodeTablesRequest{
|
||||
DbNodeId: params.NodeId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
tableMaps := []maps.Map{}
|
||||
for _, table := range tablesResp.DbNodeTables {
|
||||
if !table.IsBaseTable || (!table.CanClean && !table.CanDelete) {
|
||||
continue
|
||||
}
|
||||
tableMaps = append(tableMaps, maps.Map{
|
||||
"name": table.Name,
|
||||
"rows": table.Rows,
|
||||
"size": numberutils.FormatBytes(table.DataLength + table.IndexLength),
|
||||
"canDelete": table.CanDelete,
|
||||
"canClean": table.CanClean,
|
||||
"comment": table.Comment,
|
||||
})
|
||||
}
|
||||
this.Data["tables"] = tableMaps
|
||||
this.Success()
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
}
|
||||
|
||||
// 创建日志
|
||||
defer this.CreateLog(oplogs.LevelInfo, "创建数据库节点 %d", createResp.NodeId)
|
||||
defer this.CreateLog(oplogs.LevelInfo, "创建数据库节点 %d", createResp.DbNodeId)
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func (this *DeleteAction) RunPost(params struct {
|
||||
// 创建日志
|
||||
defer this.CreateLog(oplogs.LevelInfo, "删除数据库节点 %d", params.NodeId)
|
||||
|
||||
_, err := this.RPC().DBNodeRPC().DeleteDBNode(this.AdminContext(), &pb.DeleteDBNodeRequest{NodeId: params.NodeId})
|
||||
_, err := this.RPC().DBNodeRPC().DeleteDBNode(this.AdminContext(), &pb.DeleteDBNodeRequest{DbNodeId: params.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
|
||||
27
internal/web/actions/default/db/deleteTable.go
Normal file
27
internal/web/actions/default/db/deleteTable.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteTableAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteTableAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
Table string
|
||||
}) {
|
||||
defer this.CreateLogInfo("删除数据库节点 %d 数据表 %s", params.NodeId, params.Table)
|
||||
|
||||
_, err := this.RPC().DBNodeRPC().DeleteDBNodeTable(this.AdminContext(), &pb.DeleteDBNodeTableRequest{
|
||||
DbNodeId: params.NodeId,
|
||||
DbNodeTable: params.Table,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
@@ -32,7 +33,7 @@ func (this *IndexAction) RunGet(params struct{}) {
|
||||
return
|
||||
}
|
||||
nodeMaps := []maps.Map{}
|
||||
for _, node := range listResp.Nodes {
|
||||
for _, node := range listResp.DbNodes {
|
||||
nodeMaps = append(nodeMaps, maps.Map{
|
||||
"id": node.Id,
|
||||
"isOn": node.IsOn,
|
||||
@@ -40,6 +41,11 @@ func (this *IndexAction) RunGet(params struct{}) {
|
||||
"host": node.Host,
|
||||
"port": node.Port,
|
||||
"database": node.Database,
|
||||
"status": maps.Map{
|
||||
"isOk": node.Status.IsOk,
|
||||
"error": node.Status.Error,
|
||||
"size": numberutils.FormatBytes(node.Status.Size),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ func init() {
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
GetPost("/updatePopup", new(UpdatePopupAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
GetPost("/cleanPopup", new(CleanPopupAction)).
|
||||
Post("/deleteTable", new(DeleteTableAction)).
|
||||
Post("/truncateTable", new(TruncateTableAction)).
|
||||
|
||||
EndAll()
|
||||
})
|
||||
|
||||
27
internal/web/actions/default/db/truncateTable.go
Normal file
27
internal/web/actions/default/db/truncateTable.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type TruncateTableAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *TruncateTableAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
Table string
|
||||
}) {
|
||||
defer this.CreateLogInfo("清空数据库节点 %d 数据表 %s 数据", params.NodeId, params.Table)
|
||||
|
||||
_, err := this.RPC().DBNodeRPC().TruncateDBNodeTable(this.AdminContext(), &pb.TruncateDBNodeTableRequest{
|
||||
DbNodeId: params.NodeId,
|
||||
DbNodeTable: params.Table,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
@@ -19,13 +19,13 @@ func (this *UpdatePopupAction) Init() {
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
nodeResp, err := this.RPC().DBNodeRPC().FindEnabledDBNode(this.AdminContext(), &pb.FindEnabledDBNodeRequest{NodeId: params.NodeId})
|
||||
nodeResp, err := this.RPC().DBNodeRPC().FindEnabledDBNode(this.AdminContext(), &pb.FindEnabledDBNodeRequest{DbNodeId: params.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
node := nodeResp.Node
|
||||
node := nodeResp.DbNode
|
||||
if node == nil {
|
||||
this.NotFound("dbNode", params.NodeId)
|
||||
return
|
||||
@@ -78,7 +78,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
Require("请输入连接数据库的用户名")
|
||||
|
||||
_, err := this.RPC().DBNodeRPC().UpdateDBNode(this.AdminContext(), &pb.UpdateDBNodeRequest{
|
||||
NodeId: params.NodeId,
|
||||
DbNodeId: params.NodeId,
|
||||
IsOn: params.IsOn,
|
||||
Name: params.Name,
|
||||
Description: params.Description,
|
||||
|
||||
Reference in New Issue
Block a user