feat: add truncate query handling in migration process; update job configuration to remove commented truncate SQL

This commit is contained in:
2026-04-21 11:40:02 -05:00
parent aa71eeb5c1
commit bd51223855
3 changed files with 23 additions and 3 deletions

View File

@@ -135,6 +135,7 @@ func processMigrationJobs(
transformer,
loader,
job,
targetDb.GetDialect(),
)
chJobResults <- res

View File

@@ -18,6 +18,20 @@ import (
"golang.org/x/sync/errgroup"
)
func buildTruncateQuery(targetDbType, schema, table, truncateMethod string) string {
if truncateMethod == "DELETE" {
if targetDbType == "postgres" {
return fmt.Sprintf(`DELETE FROM "%s"."%s"`, schema, table)
}
return fmt.Sprintf(`DELETE FROM [%s].[%s]`, schema, table)
}
if targetDbType == "postgres" {
return fmt.Sprintf(`TRUNCATE TABLE "%s"."%s"`, schema, table)
}
return fmt.Sprintf(`TRUNCATE TABLE [%s].[%s]`, schema, table)
}
func processMigrationJob(
ctx context.Context,
targetDbWrapper dbwrapper.DbWrapper,
@@ -27,6 +41,7 @@ func processMigrationJob(
transformer etl.Transformer,
loader etl.Loader,
job config.Job,
targetDbType string,
) models.JobResult {
localCtx, cancel := context.WithCancel(ctx)
defer cancel()
@@ -67,7 +82,13 @@ func processMigrationJob(
return result
}
for _, query := range job.PreSQL {
preSqlQueries := job.PreSQL
if job.TruncateTarget {
truncateQuery := buildTruncateQuery(targetDbType, job.TargetTable.Schema, job.TargetTable.Table, job.TruncateMethod)
preSqlQueries = append([]string{truncateQuery}, job.PreSQL...)
}
for _, query := range preSqlQueries {
if _, err := targetDbWrapper.Exec(localCtx, query); err != nil {
result.Error = err
return result