feat: add configuration parsing and job definitions

Add a YAML config schema for migration jobs (source/target schema, table, primary key, options) and parse it at startup.
This commit is contained in:
2026-04-10 14:00:00 -05:00
parent 4f181269a4
commit 1f8689cdfc
16 changed files with 1226 additions and 30 deletions

View File

@@ -1,25 +1,49 @@
package main
import (
"context"
"time"
log "github.com/sirupsen/logrus"
)
type MigrationJob struct {
Schema string
Table string
Schema string
Table string
PrimaryKey string
}
var migrationJobs []MigrationJob = []MigrationJob{
{
Schema: "demo",
Table: "users",
Schema: "demo",
Table: "users",
PrimaryKey: "id",
},
{
Schema: "analytics",
Table: "events",
PrimaryKey: "ID_events",
},
}
const (
NumExtractors int = 4
NumLoaders int = 8
ChunkSize int = 25000
QueueSize int = 8
ChunksPerBatch int = 16
RowsPerBatch int64 = int64(ChunkSize * ChunksPerBatch)
)
func main() {
configureLog()
log.Info("Starting migration...")
// log.Debugf("Migration jobs: %+v", migrationJobs)
startTime := time.Now()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
log.Info("=== Starting migration ===")
log.Infof("Number of loaders: %d, Chunk size: %d", NumLoaders, ChunkSize)
sourceDb, targetDb, connError := connectToDatabases()
if connError != nil {
@@ -30,9 +54,11 @@ func main() {
defer targetDb.Close()
for _, job := range migrationJobs {
log.Infof("Processing job: %+v", job)
processMigrationJob(sourceDb, targetDb, job)
log.Infof(">>> Processing job: %s.%s <<<", job.Schema, job.Table)
processMigrationJob(ctx, sourceDb, targetDb, job)
}
log.Info("Migration completed successfully!")
totalDuration := time.Since(startTime)
log.Infof("=== Migration completed successfully! ===")
log.Infof("Total migration time: %v", totalDuration)
}