feat: refactor migration job structure to use SourceTableInfo and TargetTableInfo for improved configuration handling
This commit is contained in:
@@ -1,77 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v3"
|
||||
"git.ksdemosapps.com/kylesoda/go-migrate/internal/app/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type RetryConfig struct {
|
||||
Attempts int `yaml:"attempts"`
|
||||
}
|
||||
func main() {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
type JobConfig struct {
|
||||
MaxExtractors int `yaml:"max_extractors"`
|
||||
MaxLoaders int `yaml:"max_loaders"`
|
||||
QueueSize int `yaml:"queue_size"`
|
||||
ChunkSize int `yaml:"chunk_size"`
|
||||
ChunksPerBatch int `yaml:"chunks_per_batch"`
|
||||
TruncateTarget bool `yaml:"truncate_target"`
|
||||
TruncateMethod string `yaml:"truncate_method"`
|
||||
Retry RetryConfig `yaml:"retry"`
|
||||
}
|
||||
|
||||
type SourceDbInfo struct {
|
||||
Schema string `yaml:"schema"`
|
||||
Table string `yaml:"table"`
|
||||
PrimaryKey string `yaml:"primary_key"`
|
||||
}
|
||||
|
||||
type TargetDbInfo struct {
|
||||
Schema string `yaml:"schema"`
|
||||
Table string `yaml:"table"`
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
Name string `yaml:"name"`
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Source SourceDbInfo `yaml:"source"`
|
||||
Target TargetDbInfo `yaml:"target"`
|
||||
PreSQL []string `yaml:"pre_sql"`
|
||||
PostSQL []string `yaml:"post_sql"`
|
||||
JobConfig `yaml:",inline"`
|
||||
}
|
||||
|
||||
type MigrationConfig struct {
|
||||
MaxParallelWorkers int `yaml:"max_parallel_workers"`
|
||||
Defaults JobConfig `yaml:"defaults"`
|
||||
Jobs []Job `yaml:"jobs"`
|
||||
}
|
||||
|
||||
type rawConfig struct {
|
||||
maxParallelWorkers int `yaml:"max_parallel_workers"`
|
||||
defaults JobConfig `yaml:"defaults"`
|
||||
jobs []yaml.Node `yaml:"jobs"`
|
||||
}
|
||||
|
||||
func (c *MigrationConfig) UnmarshalYAML(value *yaml.Node) error {
|
||||
var raw rawConfig
|
||||
if err := value.Decode(&raw); err != nil {
|
||||
return err
|
||||
migrationConfig, err := config.ReadMigrationConfig()
|
||||
if err != nil {
|
||||
log.Fatalf("error leyendo configuracion: %v", err)
|
||||
}
|
||||
|
||||
c.MaxParallelWorkers = raw.maxParallelWorkers
|
||||
c.Defaults = raw.defaults
|
||||
|
||||
for _, node := range raw.jobs {
|
||||
job := Job{
|
||||
JobConfig: raw.defaults,
|
||||
}
|
||||
|
||||
if err := node.Decode(&job); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Jobs = append(c.Jobs, job)
|
||||
}
|
||||
|
||||
return nil
|
||||
log.Debugf("Config: %+v", migrationConfig)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user