Skip to content

Commit

Permalink
Add logs to initDatabaseSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
roger2hk committed Jul 31, 2024
1 parent 8e20b22 commit 1b4de10
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmd/example-mysql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
}

0 comments on commit 1b4de10

Please sign in to comment.