From 9964ef819b20b13552f272a2a91a665ab6ff8d01 Mon Sep 17 00:00:00 2001 From: Kylesoda <249518290+kylesoda@users.noreply.github.com> Date: Tue, 21 Apr 2026 12:30:40 -0500 Subject: [PATCH] feat: refactor migration job to use preSQL and postSQL from TargetTable; update config structure for job definitions --- cmd/go_migrate/process.go | 6 +++--- config.yaml | 12 ++++++------ internal/app/config/migration.go | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cmd/go_migrate/process.go b/cmd/go_migrate/process.go index 574d17a..2b80571 100644 --- a/cmd/go_migrate/process.go +++ b/cmd/go_migrate/process.go @@ -82,10 +82,10 @@ func processMigrationJob( return result } - preSqlQueries := job.PreSQL + preSqlQueries := job.TargetTable.PreSQL if job.TruncateTarget { 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 { @@ -238,7 +238,7 @@ func processMigrationJob( cancel() }() - for _, query := range job.PostSQL { + for _, query := range job.TargetTable.PostSQL { if _, err := targetDbWrapper.Exec(localCtx, query); err != nil { result.Error = err return result diff --git a/config.yaml b/config.yaml index d3a94c7..a75a3aa 100644 --- a/config.yaml +++ b/config.yaml @@ -28,8 +28,8 @@ jobs: target: schema: Cartografia table: MANZANA - pre_sql: - - 'SELECT 1' + pre_sql: + - 'SELECT 1' range: min: 1000000 max: 2000000 @@ -45,7 +45,7 @@ jobs: target: schema: Red table: PUERTO - pre_sql: - - 'SELECT 1' - post_sql: - - "SELECT 1" + pre_sql: + - 'SELECT 1' + post_sql: + - "SELECT 1" diff --git a/internal/app/config/migration.go b/internal/app/config/migration.go index 873967b..e76c14f 100644 --- a/internal/app/config/migration.go +++ b/internal/app/config/migration.go @@ -33,15 +33,17 @@ type TableInfo struct { Table string `yaml:"table"` } -type TargetTableInfo struct { - TableInfo `yaml:",inline"` -} - type SourceTableInfo struct { TableInfo `yaml:",inline"` PrimaryKey string `yaml:"primary_key"` } +type TargetTableInfo struct { + TableInfo `yaml:",inline"` + PreSQL []string `yaml:"pre_sql"` + PostSQL []string `yaml:"post_sql"` +} + type RangeConfig struct { Min int64 `yaml:"min"` Max int64 `yaml:"max"` @@ -54,8 +56,6 @@ type Job struct { Enabled bool `yaml:"enabled"` SourceTable SourceTableInfo `yaml:"source"` TargetTable TargetTableInfo `yaml:"target"` - PreSQL []string `yaml:"pre_sql"` - PostSQL []string `yaml:"post_sql"` JobConfig `yaml:",inline"` Range RangeConfig `yaml:"range"` }