Skip to content

Add DB config validation for required username on postgres/mysql#14

Merged
slhmy merged 2 commits intomainfrom
copilot/check-db-config-before-connect
Feb 8, 2026
Merged

Add DB config validation for required username on postgres/mysql#14
slhmy merged 2 commits intomainfrom
copilot/check-db-config-before-connect

Conversation

Copy link
Contributor

Copilot AI commented Feb 7, 2026

Databases like PostgreSQL and MySQL require a username for connection. Previously, an empty username would result in a cryptic connection error. This adds upfront validation with a clear error message.

Changes

  • Added Validate() method to gorm.Config that checks driver-specific requirements
  • postgres and mysql drivers now require non-empty username
  • sqlite is exempt (no authentication)
  • Validation runs in NewDB() before connection attempt
cfg := gorm.Config{
    Driver: "postgres",
    Host:   "localhost",
    // Username: "", // empty - will now panic with "username is required for postgres driver"
}
db := gorm.NewDB(cfg)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ysql

Co-authored-by: slhmy <31381093+slhmy@users.noreply.github.com>
Copilot AI changed the title [WIP] Check database config before establishing connection Add DB config validation for required username on postgres/mysql Feb 7, 2026
Copilot AI requested a review from slhmy February 7, 2026 02:19
@slhmy slhmy marked this pull request as ready for review February 8, 2026 09:33
@slhmy slhmy merged commit 6463ce3 into main Feb 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants