diff --git a/internal/infra/db/ch/clickhouse.go b/internal/infra/db/ch/clickhouse.go index 769cb42..c9ad3b4 100644 --- a/internal/infra/db/ch/clickhouse.go +++ b/internal/infra/db/ch/clickhouse.go @@ -59,11 +59,17 @@ func (d *ClickHouseDB) InitDB() { log.Printf("connected to database") if d.autoMigrate { - err = d.db.AutoMigrate(d.models...) - if err != nil { - log.Fatalf("failed to auto-migrate: %v", err) + for _, model := range d.models { + if !d.db.Migrator().HasTable(model) { + err = d.db.AutoMigrate(model) + if err != nil { + log.Fatalf("failed to auto-migrate model %v: %v", model, err) + } + log.Printf("auto-migrated model: %v", model) + } else { + log.Printf("Table already exists for model: %v. Skipping migration.", model) + } } - log.Printf("auto-migrate complete") } else { log.Println("Manual migration mode enabled. Skipping auto-migration.") } diff --git a/internal/tools/panics/handler.go b/internal/tools/panics/handler.go index fd57c37..f6416b1 100644 --- a/internal/tools/panics/handler.go +++ b/internal/tools/panics/handler.go @@ -1,12 +1,15 @@ package panics -import "github.com/rs/zerolog/log" +import ( + "github.com/rs/zerolog/log" + "runtime/debug" +) // DontPanic is a utility function that handles and logs panics. // It recovers from a panic, if one occurs, and logs the panic message. // This function is useful for ensuring that panics do not crash the application. func DontPanic() { if r := recover(); r != nil { - log.Printf("Recovered from panic: %v\n", r) + log.Printf("Recovered from panic: %v\n%s", r, debug.Stack()) } }