feat: refactor models to improve type handling and enhance error management across migration processes

This commit is contained in:
2026-04-10 19:27:27 -05:00
parent c2ea84bfcf
commit ca621352c9
7 changed files with 121 additions and 44 deletions

View File

@@ -10,6 +10,8 @@ import (
"time"
"git.ksdemosapps.com/kylesoda/go-migrate/internal/app/config"
"git.ksdemosapps.com/kylesoda/go-migrate/internal/app/custom_errors"
"git.ksdemosapps.com/kylesoda/go-migrate/internal/app/models"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
@@ -21,16 +23,16 @@ func loadRowsPostgres(
ctx context.Context,
db *pgxpool.Pool,
tableInfo config.TargetTableInfo,
columns []ColumnType,
chChunksIn <-chan Chunk,
columns []models.ColumnType,
chChunksIn <-chan models.Chunk,
chErrorsOut chan<- LoaderError,
chJobErrorsOut chan<- JobError,
chJobErrorsOut chan<- custom_errors.JobError,
wgActiveChunks *sync.WaitGroup,
rowsLoaded *int64,
) {
tableId := pgx.Identifier{tableInfo.Schema, tableInfo.Table}
colNames := Map(columns, func(col ColumnType) string {
return col.name
colNames := Map(columns, func(col models.ColumnType) string {
return col.Name()
})
for {
@@ -58,9 +60,9 @@ func loadChunkPostgres(
db *pgxpool.Pool,
identifier pgx.Identifier,
colNames []string,
chunk Chunk,
chunk models.Chunk,
chErrorsOut chan<- LoaderError,
chJobErrorsOut chan<- JobError,
chJobErrorsOut chan<- custom_errors.JobError,
wgActiveChunks *sync.WaitGroup,
rowsLoaded *int64,
) (abort bool) {
@@ -77,7 +79,7 @@ func loadChunkPostgres(
if errors.As(err, &pgErr) {
if pgErr.Code == "23505" {
select {
case chJobErrorsOut <- JobError{
case chJobErrorsOut <- custom_errors.JobError{
ShouldCancelJob: true,
Msg: fmt.Sprintf("Fatal error in table %s", identifier.Sanitize()),
Prev: err,