Fix: Remove hardcoded default database name and utilize DBDefaultDatabase config #29

Closed
opened 2026-02-16 00:19:14 -05:00 by yindo · 1 comment
Owner

Originally created by @faye1225 on GitHub (Mar 8, 2025).

Issue Description

In internal/db/init.go, the database initialization code has two issues that need to be addressed:

  1. The default database name "postgres" is hardcoded in the Init function:
func Init(config *app.Config) {
    err := initDifyPluginDB(
        config.DBHost,
        int(config.DBPort),
        config.DBDatabase,
        "postgres",  // Hardcoded default database name
        config.DBUsername,
        config.DBPassword,
        config.DBSslMode,
    )
}
  1. Despite having a DBDefaultDatabase field in the configuration:
DBDefaultDatabase string `envconfig:"DB_DEFAULT_DATABASE" validate:"required"`

This configuration value is not being used.

Impact

  • Reduces configuration flexibility
  • Makes the code less maintainable
  • Creates confusion as the configuration value exists but is not used
  • May cause issues when trying to use a different default database

Proposed Solution

Replace the hardcoded "postgres" with the configured DBDefaultDatabase:

func Init(config *app.Config) {
    err := initDifyPluginDB(
        config.DBHost,
        int(config.DBPort),
        config.DBDatabase,
        config.DBDefaultDatabase,  // Use configured default database
        config.DBUsername,
        config.DBPassword,
        config.DBSslMode,
    )
}

This change will:

  1. Remove the hardcoded value
  2. Make the code more configurable
  3. Properly utilize the existing configuration field
  4. Make the behavior more predictable and documented through configuration
Originally created by @faye1225 on GitHub (Mar 8, 2025). ## Issue Description In `internal/db/init.go`, the database initialization code has two issues that need to be addressed: 1. The default database name "postgres" is hardcoded in the `Init` function: ```go func Init(config *app.Config) { err := initDifyPluginDB( config.DBHost, int(config.DBPort), config.DBDatabase, "postgres", // Hardcoded default database name config.DBUsername, config.DBPassword, config.DBSslMode, ) } ``` 2. Despite having a `DBDefaultDatabase` field in the configuration: ```go DBDefaultDatabase string `envconfig:"DB_DEFAULT_DATABASE" validate:"required"` ``` This configuration value is not being used. ## Impact - Reduces configuration flexibility - Makes the code less maintainable - Creates confusion as the configuration value exists but is not used - May cause issues when trying to use a different default database ## Proposed Solution Replace the hardcoded "postgres" with the configured `DBDefaultDatabase`: ```go func Init(config *app.Config) { err := initDifyPluginDB( config.DBHost, int(config.DBPort), config.DBDatabase, config.DBDefaultDatabase, // Use configured default database config.DBUsername, config.DBPassword, config.DBSslMode, ) } ``` This change will: 1. Remove the hardcoded value 2. Make the code more configurable 3. Properly utilize the existing configuration field 4. Make the behavior more predictable and documented through configuration
yindo closed this issue 2026-02-16 00:19:14 -05:00
Author
Owner

@Yeuoly commented on GitHub (Mar 10, 2025):

#77 Done

@Yeuoly commented on GitHub (Mar 10, 2025): #77 Done
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-plugin-daemon#29