feat: refactor migration job to use preSQL and postSQL from TargetTable; update config structure for job definitions
This commit is contained in:
@@ -82,10 +82,10 @@ func processMigrationJob(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
preSqlQueries := job.PreSQL
|
preSqlQueries := job.TargetTable.PreSQL
|
||||||
if job.TruncateTarget {
|
if job.TruncateTarget {
|
||||||
truncateQuery := buildTruncateQuery(targetDbType, job.TargetTable.Schema, job.TargetTable.Table, job.TruncateMethod)
|
truncateQuery := buildTruncateQuery(targetDbType, job.TargetTable.Schema, job.TargetTable.Table, job.TruncateMethod)
|
||||||
preSqlQueries = append([]string{truncateQuery}, job.PreSQL...)
|
preSqlQueries = append([]string{truncateQuery}, job.TargetTable.PreSQL...)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, query := range preSqlQueries {
|
for _, query := range preSqlQueries {
|
||||||
@@ -238,7 +238,7 @@ func processMigrationJob(
|
|||||||
cancel()
|
cancel()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for _, query := range job.PostSQL {
|
for _, query := range job.TargetTable.PostSQL {
|
||||||
if _, err := targetDbWrapper.Exec(localCtx, query); err != nil {
|
if _, err := targetDbWrapper.Exec(localCtx, query); err != nil {
|
||||||
result.Error = err
|
result.Error = err
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -33,15 +33,17 @@ type TableInfo struct {
|
|||||||
Table string `yaml:"table"`
|
Table string `yaml:"table"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TargetTableInfo struct {
|
|
||||||
TableInfo `yaml:",inline"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SourceTableInfo struct {
|
type SourceTableInfo struct {
|
||||||
TableInfo `yaml:",inline"`
|
TableInfo `yaml:",inline"`
|
||||||
PrimaryKey string `yaml:"primary_key"`
|
PrimaryKey string `yaml:"primary_key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TargetTableInfo struct {
|
||||||
|
TableInfo `yaml:",inline"`
|
||||||
|
PreSQL []string `yaml:"pre_sql"`
|
||||||
|
PostSQL []string `yaml:"post_sql"`
|
||||||
|
}
|
||||||
|
|
||||||
type RangeConfig struct {
|
type RangeConfig struct {
|
||||||
Min int64 `yaml:"min"`
|
Min int64 `yaml:"min"`
|
||||||
Max int64 `yaml:"max"`
|
Max int64 `yaml:"max"`
|
||||||
@@ -54,8 +56,6 @@ type Job struct {
|
|||||||
Enabled bool `yaml:"enabled"`
|
Enabled bool `yaml:"enabled"`
|
||||||
SourceTable SourceTableInfo `yaml:"source"`
|
SourceTable SourceTableInfo `yaml:"source"`
|
||||||
TargetTable TargetTableInfo `yaml:"target"`
|
TargetTable TargetTableInfo `yaml:"target"`
|
||||||
PreSQL []string `yaml:"pre_sql"`
|
|
||||||
PostSQL []string `yaml:"post_sql"`
|
|
||||||
JobConfig `yaml:",inline"`
|
JobConfig `yaml:",inline"`
|
||||||
Range RangeConfig `yaml:"range"`
|
Range RangeConfig `yaml:"range"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user