Skip to content

Commit

Permalink
Defer createIndices
Browse files Browse the repository at this point in the history
  • Loading branch information
Lun4m committed Nov 20, 2024
1 parent 3c7456d commit f3216e1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions migrations/kdvh/import/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ func (config *Config) Execute([]string) error {
dropIndices(pool)
}

// Recreate indices even in case the main function panics
defer func() {
r := recover()
if config.Reindex {
createIndices(pool)
}

if r != nil {
panic(r)
}
}()

for _, table := range kdvh.Tables {
if len(config.Tables) > 0 && !slices.Contains(config.Tables, table.TableName) {
continue
Expand All @@ -69,10 +81,6 @@ func (config *Config) Execute([]string) error {
}

log.SetOutput(os.Stdout)
if config.Reindex {
createIndices(pool)
}

slog.Info("Import complete!")
return nil
}
Expand Down

0 comments on commit f3216e1

Please sign in to comment.