From 1b4de10e9cbfc0bb492efcd6dcef3a3163fcbac1 Mon Sep 17 00:00:00 2001 From: roger2hk Date: Wed, 31 Jul 2024 10:01:00 +0000 Subject: [PATCH] Add logs to `initDatabaseSchema` --- cmd/example-mysql/main.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/example-mysql/main.go b/cmd/example-mysql/main.go index f3eeca1a..7ed6a1cc 100644 --- a/cmd/example-mysql/main.go +++ b/cmd/example-mysql/main.go @@ -248,11 +248,17 @@ func parseTileIndexWidth(index string) (uint64, uint64, error) { func initDatabaseSchema(ctx context.Context) { if *initSchemaPath != "" { + klog.Infof("Initializing database schema") + db, err := sql.Open("mysql", *mysqlURI+"?multiStatements=true") if err != nil { klog.Exitf("Failed to connect to DB: %v", err) } - defer db.Close() + defer func() { + if err := db.Close(); err != nil { + klog.Warningf("Failed to close db: %v", err) + } + }() rawSchema, err := os.ReadFile(*initSchemaPath) if err != nil { @@ -262,10 +268,6 @@ func initDatabaseSchema(ctx context.Context) { klog.Exitf("Failed to execute init database schema: %v", err) } - defer func() { - if err := db.Close(); err != nil { - klog.Warningf("Failed to close db: %v", err) - } - }() + klog.Infof("Database schema initialized") } }