Skip to content

Commit 9d51f45

Browse files
authored
fix: all cli command try to connect to cache and database (#438)
**Describe the pull request** This pull request addresses an issue where all command-line interface (CLI) commands attempt to connect to the cache and database, regardless of whether these connections are necessary for the command. The fix involves updating the CLI command behavior, so that each command only attempts to connect to the cache and database when required. **Checklist** - [x] I have linked the relative issue to this pull request - [x] I have made the modifications or added tests related to my PR - [x] I have added/updated the documentation for my RP - [x] I put my PR in Ready for Review only when all the checklist is checked **Breaking changes ?** no
1 parent f49eb31 commit 9d51f45

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

cmd/root.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var rootCmd = &cobra.Command{
2525

2626
keyValueStoreUrl := viper.GetString("keyvalue-store-url")
2727
if keyValueStoreUrl != "" {
28+
log.Info().Msg("Key-value store URL is set, connecting to it...")
2829
cacheClient, err = cache.NewClient(viper.GetString("keyvalue-store-url"))
2930
if err != nil {
3031
log.Fatal().Err(err).Msg("failed to create cache")
@@ -33,12 +34,16 @@ var rootCmd = &cobra.Command{
3334
cmd.SetContext(context.WithValue(cmd.Context(), keyValueCtxKey{}, cacheClient))
3435
}
3536

36-
if modelsutils.Connect(cacheClient) != nil {
37-
log.Fatal().Msg("Failed to connect to database")
38-
}
37+
if viper.GetString("database-url") != "" {
38+
log.Info().Msg("Database URL is set, connecting to database...")
39+
if modelsutils.Connect(cacheClient) != nil {
40+
log.Fatal().Msg("Failed to connect to database")
41+
}
3942

40-
if err := modelsutils.Migrate(); err != nil {
41-
log.Fatal().Err(err).Msg("failed to migrate database")
43+
log.Info().Msg("Migrating database...")
44+
if err := modelsutils.Migrate(); err != nil {
45+
log.Fatal().Err(err).Msg("failed to migrate database")
46+
}
4247
}
4348
},
4449
}

0 commit comments

Comments
 (0)