Skip to content

Commit

Permalink
fix: move extra export to bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
thoas committed Jan 19, 2024
1 parent db593cf commit bf82328
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/mover/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func main() {
} else {
logger, _ = zap.NewProduction()
}
// nolint:errcheck
//nolint:errcheck
defer logger.Sync()

var cfg config.Config
Expand Down
18 changes: 9 additions & 9 deletions etl/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"strings"

Expand Down Expand Up @@ -114,22 +114,22 @@ func (e *Engine) Extract(ctx context.Context, outputPath, query string) error {
return fmt.Errorf("unable to extract %s (query %s): %w", tableName, query, err)
}

for tableName := range cache {
if err := e.extract(ctx, outputPath, e.schema[tableName], cache[tableName]); err != nil {
return fmt.Errorf("unable to extract rows from table %s: %w", tableName, err)
}
}

for i := range e.config.Extra {
tableName := e.config.Extra[i].TableName
query, _ := lk.Select(lk.Raw("*")).
From(tableName).Query()
cache, err = extractor.Handle(ctx, e.schema[tableName], query)
_, err = extractor.Handle(ctx, e.schema[tableName], query)
if err != nil {
return fmt.Errorf("unable to extract %s (query %s): %w", tableName, query, err)
}
}

for tableName := range cache {
if err := e.extract(ctx, outputPath, e.schema[tableName], cache[tableName]); err != nil {
return fmt.Errorf("unable to extract rows from table %s: %w", tableName, err)
}
}

return nil
}

Expand All @@ -155,7 +155,7 @@ func (e *Engine) extract(ctx context.Context, outputPath string, schema config.S
}

filePath := path.Join(outputPath, table.Name+extensionFormat)
if err := ioutil.WriteFile(filePath, output, 0644); err != nil {
if err := os.WriteFile(filePath, output, 0644); err != nil {
return fmt.Errorf("unable to write JSON output to %s: %w", filePath, err)
}

Expand Down
4 changes: 2 additions & 2 deletions etl/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -58,7 +58,7 @@ func (l *loader) loadFile(ctx context.Context, filePath string) error {
}
defer file.Close()

content, err := ioutil.ReadAll(file)
content, err := io.ReadAll(file)
if err != nil {
return fmt.Errorf("unable to read file %s: %w", filePath, err)
}
Expand Down

0 comments on commit bf82328

Please sign in to comment.