Skip to content

Commit

Permalink
add dataManger module, support mysql data migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxinwang committed Dec 8, 2023
1 parent 17606f7 commit e7674d6
Show file tree
Hide file tree
Showing 11 changed files with 633 additions and 39 deletions.
26 changes: 26 additions & 0 deletions handler/DataMigrateJobHandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package handler

import (
"github.com/gin-gonic/gin"
"horizon/service"
)

func DataMigrateJobGet(c *gin.Context) {
service.DataMigrateJobSelectByList(c)
}

func DataMigrateJobIdGet(c *gin.Context) {
service.DataMigrateJobSelectById(c)
}

func DataMigrateJobPost(c *gin.Context) {
service.DataMigrateJobInsert(c)
}

func DataMigrateJobExecutePost(c *gin.Context) {
service.DataMigrateJobExecuteUpdate(c)
}

func DataMigrateJobDetailGet(c *gin.Context) {
service.DataMigrateJobDetailSelectByList(c)
}
6 changes: 5 additions & 1 deletion handler/InstanceHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func InstanceDelete(c *gin.Context) {
service.InstanceDelete(c)
}

func InstanceDdGet(c *gin.Context) {
func InstanceDbGet(c *gin.Context) {
service.InstanceDbSelectByInstId(c)
}

func InstanceDbTableGet(c *gin.Context) {
service.InstanceDbTableSelectByInstIdDb(c)
}
28 changes: 28 additions & 0 deletions model/DataManager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package model

import "time"

type DataMigrateJob struct {
ID uint `gorm:"primaryKey;comment:主键ID" json:"id"`
Name string `gorm:"type:varchar(50);not null;comment:任务名称" json:"name"`
Describe string `gorm:"type:varchar(255);not null;comment:描述" json:"describe"`
SourceInstId string `gorm:"type:varchar(20);not null;comment:源实例ID" json:"sourceInstId"`
SourceDb string `gorm:"type:varchar(20);not null;comment:源数据库" json:"sourceDb"`
TargetInstId string `gorm:"type:varchar(20);not null;comment:目的实例ID" json:"targetInstId"`
TargetDb string `gorm:"type:varchar(20);not null;comment:目的数据库" json:"targetDb"`
Status string `gorm:"type:enum('NotStart', 'Running', 'Error', 'Finished');default:'NotStart';not null;comment:任务状态" json:"status"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间" json:"updatedAt"`
}

type DataMigrateJobDetail struct {
ID uint `gorm:"primaryKey;comment:主键ID" json:"id"`
DataMigrateJobId uint `gorm:"type:int;comment:迁移任务主键ID" json:"dataMigrateJobId"`
TableName string `gorm:"type:varchar(50);not null;comment:表名称" json:"tableName"`
Status string `gorm:"type:enum('NotStart', 'Running', 'Error', 'Finished');default:'NotStart';not null;comment:同步状态" json:"status"`
EstimateRows uint `gorm:"type:int;comment:预估行数" json:"estimateRows"`
CompletedRows uint `gorm:"type:int;comment:已完成行数" json:"completedRows"`
ErrorMsg string `gorm:"type:varchar(1000);not null;comment:错误信息" json:"errorMsg"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间" json:"updatedAt"`
}
23 changes: 0 additions & 23 deletions model/DataMigrate.go

This file was deleted.

5 changes: 5 additions & 0 deletions model/Workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type WorkflowStatus string
type WorkflowSqlAuditStatus string
type WorkflowSqlAuditLevel string
type WorkflowSqlExecutionStatus string
type WorkflowType string

const (
WorkflowStatusPendingAudit WorkflowStatus = "PendingAudit" // 待审核
Expand All @@ -39,6 +40,9 @@ const (

WorkflowSqlExecutionStatusFailed WorkflowSqlExecutionStatus = "Failed" // 执行失败
WorkflowSqlExecutionStatusSuccessfully WorkflowSqlExecutionStatus = "Successfully" // 执行成功

SqlAuditType WorkflowType = "SqlAudit"
DataMigrateType WorkflowType = "DataMigrate"
)

type Workflow struct {
Expand All @@ -49,6 +53,7 @@ type Workflow struct {
ProjId string `gorm:"type:varchar(20);not null;comment:项目ID" json:"projId"`
InstId string `gorm:"type:varchar(20);not null;comment:实例ID" json:"instId"`
DbName string `gorm:"type:varchar(255);not null;comment:数据库名" json:"dbName"`
Type WorkflowType `gorm:"type:varchar(20);default:'SqlAudit';not null;comment:工单类型" json:"type"`
SqlContent string `gorm:"type:text;not null;comment:SQL内容" json:"sqlContent"`
UserName string `gorm:"type:varchar(50);not null;comment:用户名" json:"userName"`
ScheduledAt *time.Time `gorm:"type:datetime;default null;comment:定时调度时间" json:"scheduledAt"`
Expand Down
4 changes: 3 additions & 1 deletion model/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ func InitDb() {
&WorkflowTemplate{},
&WorkflowTemplateDetail{},
&WorkflowRecord{},
&WorkflowSqlDetail{})
&WorkflowSqlDetail{},
&DataMigrateJob{},
&DataMigrateJobDetail{})
if err != nil {
log.Fatal(err.Error())
}
Expand Down
13 changes: 12 additions & 1 deletion router/Router.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func commonRouter(r *gin.Engine) {
instance.POST("add", handler.InstancePost)
instance.PUT("edit", handler.InstancePut)
instance.DELETE("delete/:id", handler.InstanceDelete)
instance.GET("db/:instId", handler.InstanceDdGet)
instance.GET("db/:instId", handler.InstanceDbGet)
instance.GET("db/table", handler.InstanceDbTableGet)

// inspection group
inspection := api.Group("/inspection", authMiddleware.MiddlewareFunc())
Expand Down Expand Up @@ -129,4 +130,14 @@ func commonRouter(r *gin.Engine) {
configCenterInstanceConfig := configCenter.Group("/config", authMiddleware.MiddlewareFunc())
configCenterInstanceConfig.GET("query", handler.ConfigCenterInstanceConfigGet)
configCenterInstanceConfig.GET("detail", handler.ConfigCenterInstanceConfigDataGet)

// dataManger group
dataManger := api.Group("/dataManger", authMiddleware.MiddlewareFunc())
dataMigrateJob := dataManger.Group("/dataMigrateJob", authMiddleware.MiddlewareFunc())
dataMigrateJob.GET("query", handler.DataMigrateJobGet)
dataMigrateJob.GET("/:id", handler.DataMigrateJobIdGet)
dataMigrateJob.POST("add", handler.DataMigrateJobPost)
dataMigrateJob.POST("execute", handler.DataMigrateJobExecutePost)
dataMigrateJobDetail := dataManger.Group("/dataMigrateJobDetail", authMiddleware.MiddlewareFunc())
dataMigrateJobDetail.GET("query", handler.DataMigrateJobDetailGet)
}
Loading

0 comments on commit e7674d6

Please sign in to comment.