Skip to content

Commit

Permalink
dm: refine openapi table migrate rule source/target (#11933)
Browse files Browse the repository at this point in the history
close #4287
  • Loading branch information
River2000i authored Jan 6, 2025
1 parent 1dd87cf commit 686f8ea
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 123 deletions.
11 changes: 2 additions & 9 deletions dm/config/task_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,21 +610,14 @@ func SubTaskConfigsToOpenAPITask(subTaskConfigList []*SubTaskConfig) *openapi.Ta
ruleMap := map[string]struct{}{}
appendOneRule := func(sourceName, schemaPattern, tablePattern, targetSchema, targetTable string) {
tableMigrateRule := openapi.TaskTableMigrateRule{
Source: struct {
Schema string `json:"schema"`
SourceName string `json:"source_name"`
Table string `json:"table"`
}{
Source: openapi.TaskTableMigrateRuleSource{
Schema: schemaPattern,
SourceName: sourceName,
Table: tablePattern,
},
}
if targetSchema != "" {
tableMigrateRule.Target = &struct {
Schema *string `json:"schema,omitempty"`
Table *string `json:"table,omitempty"`
}{
tableMigrateRule.Target = &openapi.TaskTableMigrateRuleTarget{
Schema: &targetSchema,
}
if targetTable != "" {
Expand Down
39 changes: 7 additions & 32 deletions dm/config/task_converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,18 +459,11 @@ func TestConvertBetweenOpenAPITaskAndTaskConfig(t *testing.T) {
sourceSchema := task.TableMigrateRule[0].Source.Schema
targetSchema := *task.TableMigrateRule[0].Target.Schema
// only route schema
task.TableMigrateRule[0].Source = struct {
Schema string `json:"schema"`
SourceName string `json:"source_name"`
Table string `json:"table"`
}{
task.TableMigrateRule[0].Source = openapi.TaskTableMigrateRuleSource{
SourceName: source1Name,
Schema: sourceSchema,
}
task.TableMigrateRule[0].Target = &struct {
Schema *string `json:"schema,omitempty"`
Table *string `json:"table,omitempty"`
}{
task.TableMigrateRule[0].Target = &openapi.TaskTableMigrateRuleTarget{
Schema: &targetSchema,
}
taskCfg, err = OpenAPITaskToTaskConfig(&task, sourceCfgMap)
Expand Down Expand Up @@ -504,38 +497,24 @@ func TestConvertBetweenOpenAPITaskAndTaskConfig(t *testing.T) {
// only route table will meet error
sourceTable := "tb"
targetTable := "tb1"
task.TableMigrateRule[0].Source = struct {
Schema string `json:"schema"`
SourceName string `json:"source_name"`
Table string `json:"table"`
}{
task.TableMigrateRule[0].Source = openapi.TaskTableMigrateRuleSource{
SourceName: source1Name,
Schema: sourceSchema,
Table: sourceTable,
}
task.TableMigrateRule[0].Target = &struct {
Schema *string `json:"schema,omitempty"`
Table *string `json:"table,omitempty"`
}{
task.TableMigrateRule[0].Target = &openapi.TaskTableMigrateRuleTarget{
Table: &targetTable,
}
_, err = OpenAPITaskToTaskConfig(&task, sourceCfgMap)
require.True(t, terror.ErrConfigGenTableRouter.Equal(err))

// route both
task.TableMigrateRule[0].Source = struct {
Schema string `json:"schema"`
SourceName string `json:"source_name"`
Table string `json:"table"`
}{
task.TableMigrateRule[0].Source = openapi.TaskTableMigrateRuleSource{
SourceName: source1Name,
Schema: sourceSchema,
Table: sourceTable,
}
task.TableMigrateRule[0].Target = &struct {
Schema *string `json:"schema,omitempty"`
Table *string `json:"table,omitempty"`
}{
task.TableMigrateRule[0].Target = &openapi.TaskTableMigrateRuleTarget{
Schema: &targetSchema,
Table: &targetTable,
}
Expand Down Expand Up @@ -578,11 +557,7 @@ func TestConvertBetweenOpenAPITaskAndTaskConfig(t *testing.T) {
require.EqualValues(t, taskAfterConvert, &task)

// no route and sync one schema
task.TableMigrateRule[0].Source = struct {
Schema string `json:"schema"`
SourceName string `json:"source_name"`
Table string `json:"table"`
}{
task.TableMigrateRule[0].Source = openapi.TaskTableMigrateRuleSource{
SourceName: source1Name,
Schema: sourceSchema,
Table: "",
Expand Down
74 changes: 37 additions & 37 deletions dm/openapi/gen.server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 21 additions & 15 deletions dm/openapi/gen.types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 33 additions & 30 deletions dm/openapi/spec/dm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,37 @@ components:
- "user"
- "enable_gtid"
- "enable"
TaskTableMigrateRuleSource:
description: source-related configuration
properties:
source_name:
type: string
description: source name
example: "source-name"
schema:
type: string
description: schema name, wildcard support
example: "db-*"
table:
type: string
description: table name, wildcard support
example: "tb-*"
required:
- "source_name"
- "schema"
- "table"
TaskTableMigrateRuleTarget:
type: object
description: downstream-related configuration
properties:
schema:
type: string
description: schema name, does not support wildcards
example: "db1"
table:
type: string
description: table name, does not support wildcards
example: "tb1"
ShardingGroup:
type: object
properties:
Expand Down Expand Up @@ -1646,37 +1677,9 @@ components:
description: "upstream table to downstream migrate rules"
properties:
source:
type: object
description: source-related configuration
properties:
source_name:
type: string
description: source name
example: "source-name"
schema:
type: string
description: schema name, wildcard support
example: "db-*"
table:
type: string
description: table name, wildcard support
example: "tb-*"
required:
- "source_name"
- "schema"
- "table"
$ref: "#/components/schemas/TaskTableMigrateRuleSource"
target:
type: object
description: downstream-related configuration
properties:
schema:
type: string
description: schema name, does not support wildcards
example: "db1"
table:
type: string
description: table name, does not support wildcards
example: "tb1"
$ref: "#/components/schemas/TaskTableMigrateRuleTarget"
binlog_filter_rule:
type: array
description: "filter rule name"
Expand Down

0 comments on commit 686f8ea

Please sign in to comment.