Add missing database driver in CLI#2317
Conversation
📝 WalkthroughWalkthroughAdds PostgreSQL as a selectable database driver in the interactive database settings command and implements prompts, connection-configuration, and connectivity testing for PostgreSQL during the command's execution. ChangesDatabase Settings: PostgreSQL support
sequenceDiagram
participant CLI as Console Command
participant Config as Laravel DB Config
participant PG as PostgreSQL Server
CLI->>CLI: Prompt user for pgsql host/port/db/user/password
CLI->>Config: Set database.connections._panel_command_test (driver: pgsql, params...)
CLI->>PG: Attempt getPdo() (connect)
alt Connection success
PG-->>CLI: Connection established
CLI-->>Config: Proceed / persist settings
else Connection failure
PG-->>CLI: Error/exception
CLI-->>CLI: Print error, disconnect, offer "go back"
alt User chooses retry
CLI->>CLI: Re-run prompts/flow
else
CLI-->>Caller: Exit with code 1
end
end
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/Console/Commands/Environment/DatabaseSettingsCommand.php`:
- Line 19: DATABASE_DRIVERS includes 'pgsql' but handle() lacks a pgsql branch
so selecting PostgreSQL skips prompts and connection testing; add an elseif
($this->variables['DB_CONNECTION'] === 'pgsql') block inside the handle() method
(same place as the mysql/mariadb/sqlite branches) that mirrors their interactive
flow: use config('database.connections.pgsql.host'),
config('database.connections.pgsql.port'),
config('database.connections.pgsql.database'),
config('database.connections.pgsql.username') and
config('database.connections.pgsql.password') as defaults, prompt the user for
host/port/database/username/password, write those into $this->variables (same
keys used by other branches), and invoke the same connection test routine used
by the other branches to validate the credentials before saving.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 272e284a-5253-4925-a28c-0b15f11db742
📒 Files selected for processing (1)
app/Console/Commands/Environment/DatabaseSettingsCommand.php
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
061fb11 to
4c2ca36
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
app/Console/Commands/Environment/DatabaseSettingsCommand.php (1)
62-244: 🏗️ Heavy liftConsider consolidating MySQL/MariaDB/PostgreSQL setup into a shared helper.
The three branches now have near-identical prompt/test logic. Centralizing this with a per-driver config map would reduce future drift (like missing one driver in later updates).
Refactor direction (sketch)
+// 1) Define per-driver metadata/default config paths in one map. +// 2) Reuse one method to: +// - ask host/port/database/username/password +// - build _panel_command_test connection config +// - run getPdo() + shared error/retry handling + - if ($this->variables['DB_CONNECTION'] === 'mysql') { ... } - elseif ($this->variables['DB_CONNECTION'] === 'mariadb') { ... } - elseif ($this->variables['DB_CONNECTION'] === 'pgsql') { ... } + if (in_array($this->variables['DB_CONNECTION'], ['mysql', 'mariadb', 'pgsql'], true)) { + return $this->handleSqlDriver($this->variables['DB_CONNECTION']); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/Console/Commands/Environment/DatabaseSettingsCommand.php` around lines 62 - 244, The three DB branches in DatabaseSettingsCommand handling mysql/mariadb/pgsql duplicate prompting and connection-testing logic; extract that into a shared helper (e.g., a private method gatherAndTestSqlConnection or testSqlDriverConnection) that accepts the driver identifier and a per-driver config map (driver name, default port, default database, default username, config keys like database.connections.{driver}) to perform host/port/database/username/password prompts, set the temporary '_panel_command_test' config, call $this->database->connection('_panel_command_test')->getPdo(), and handle the PDOException (including $this->database->disconnect('_panel_command_test') and the existing confirm/return behavior); then replace the mysql/mariadb/pgsql branches in handle() to call that helper with the appropriate map to remove the duplicated code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@app/Console/Commands/Environment/DatabaseSettingsCommand.php`:
- Around line 62-244: The three DB branches in DatabaseSettingsCommand handling
mysql/mariadb/pgsql duplicate prompting and connection-testing logic; extract
that into a shared helper (e.g., a private method gatherAndTestSqlConnection or
testSqlDriverConnection) that accepts the driver identifier and a per-driver
config map (driver name, default port, default database, default username,
config keys like database.connections.{driver}) to perform
host/port/database/username/password prompts, set the temporary
'_panel_command_test' config, call
$this->database->connection('_panel_command_test')->getPdo(), and handle the
PDOException (including $this->database->disconnect('_panel_command_test') and
the existing confirm/return behavior); then replace the mysql/mariadb/pgsql
branches in handle() to call that helper with the appropriate map to remove the
duplicated code.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d99926e0-db59-4c9d-8353-4f9ebb62626f
📒 Files selected for processing (1)
app/Console/Commands/Environment/DatabaseSettingsCommand.php
Unless there was an explicit reason this was missing, I think this is a bug?