Skip to content

Make --dbname and --dbuser optional when SQLite integration is active#219

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-sqlite-compatibility-issue
Open

Make --dbname and --dbuser optional when SQLite integration is active#219
Copilot wants to merge 2 commits intomainfrom
copilot/fix-sqlite-compatibility-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

wp config create unconditionally requires --dbname and --dbuser, making it impossible to create a config for a SQLite-backed WordPress install without supplying MySQL credentials that will never be used.

Changes

  • Optional synopsis params: --dbname and --dbuser are now [--dbname] / [--dbuser] in the docblock synopsis.
  • SQLite detection: New is_sqlite_integration_active() checks for SQLITE_DB_DROPIN_VERSION in wp-content/db.php (reads first 8 KB only).
  • Conditional validation: When SQLite is not detected, missing --dbname or --dbuser still produces an explicit error — existing MySQL/MariaDB behaviour is unchanged.
  • Skip MySQL check for SQLite: The mysqli connection check is bypassed entirely when SQLite is detected, so --skip-check is not required.
  • New @require-sqlite Behat scenario: Verifies wp config create succeeds without --dbname/--dbuser when the SQLite drop-in is present.
# SQLite install — now works without MySQL credentials
$ wp config create --skip-salts --skip-check
Success: Generated 'wp-config.php' file.

# MySQL install — still errors clearly if params are omitted
$ wp config create --skip-check
Error: Parameter errors:
missing --dbname parameter (Set the database name.)

Copilot AI linked an issue Apr 1, 2026 that may be closed by this pull request
@github-actions github-actions bot added bug command:config-create Related to 'config create' command scope:testing Related to testing state:unconfirmed labels Apr 1, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…n and skip MySQL check for SQLite

Agent-Logs-Url: https://github.com/wp-cli/config-command/sessions/8f9ece6b-b44b-4ac7-87e2-35bad2b2afff

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SQLite compatibility issue in db creation tests Make --dbname and --dbuser optional when SQLite integration is active Apr 1, 2026
Copilot AI requested a review from swissspidy April 1, 2026 08:59
@swissspidy swissspidy marked this pull request as ready for review April 2, 2026 11:10
@swissspidy swissspidy requested a review from a team as a code owner April 2, 2026 11:10
Copilot AI review requested due to automatic review settings April 2, 2026 11:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates wp config create to support SQLite-backed WordPress installs by allowing --dbname / --dbuser to be omitted when an SQLite integration drop-in is detected.

Changes:

  • Make --dbname and --dbuser optional in the command synopsis.
  • Detect SQLite integration via wp-content/db.php and conditionally skip MySQL parameter validation and MySQLi connection checks.
  • Add a Behat scenario to validate config creation without MySQL credentials when the SQLite drop-in is present.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Config_Command.php Adds SQLite drop-in detection, conditional required-parameter validation, and bypasses MySQLi check when SQLite is active.
features/config-create.feature Adds a Behat scenario for creating config without --dbname/--dbuser when an SQLite drop-in is present.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +226 to +231
if ( empty( $assoc_args['dbname'] ) ) {
WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbname parameter (Set the database name.)' );
}
if ( empty( $assoc_args['dbuser'] ) ) {
WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbuser parameter (Set the database user.)' );
}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current validation for missing --dbname/--dbuser changes behavior compared to WP-CLI’s synopsis validation: (1) using empty() will incorrectly reject values like --dbuser=0, and (2) calling WP_CLI::error() per-field exits on the first missing parameter so you never report both missing options together. Consider collecting missing parameters into an array and emitting a single Parameter errors: message, and check for presence/empty-string rather than empty().

Suggested change
if ( empty( $assoc_args['dbname'] ) ) {
WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbname parameter (Set the database name.)' );
}
if ( empty( $assoc_args['dbuser'] ) ) {
WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbuser parameter (Set the database user.)' );
}
$param_errors = [];
if ( ! array_key_exists( 'dbname', $assoc_args ) || $assoc_args['dbname'] === '' ) {
$param_errors[] = 'missing --dbname parameter (Set the database name.)';
}
if ( ! array_key_exists( 'dbuser', $assoc_args ) || $assoc_args['dbuser'] === '' ) {
$param_errors[] = 'missing --dbuser parameter (Set the database user.)';
}
if ( ! empty( $param_errors ) ) {
WP_CLI::error( 'Parameter errors:' . PHP_EOL . implode( PHP_EOL, $param_errors ) );
}

Copilot uses AI. Check for mistakes.
Comment on lines +1504 to +1505
if ( file_exists( $db_dropin_path ) ) {
$db_dropin_contents = file_get_contents( $db_dropin_path, false, null, 0, 8192 );
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file_get_contents() can emit PHP warnings (e.g., if wp-content/db.php exists but is not readable), which would leak noise into CLI output. Consider adding an is_readable() guard and/or suppressing warnings and handling failures explicitly to keep output clean.

Suggested change
if ( file_exists( $db_dropin_path ) ) {
$db_dropin_contents = file_get_contents( $db_dropin_path, false, null, 0, 8192 );
if ( is_readable( $db_dropin_path ) ) {
// Suppress potential warnings and handle failure explicitly to keep CLI output clean.
$db_dropin_contents = @file_get_contents( $db_dropin_path, false, null, 0, 8192 );

Copilot uses AI. Check for mistakes.
define( 'SQLITE_DB_DROPIN_VERSION', '1.0.0' );
"""

When I run `wp config create --skip-salts --skip-check`
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario includes --skip-check, so it doesn’t actually exercise the new behavior of bypassing the MySQLi connection check when SQLite is detected. To cover the new branch, run wp config create without --skip-check (while still omitting --dbname/--dbuser) and assert it succeeds.

Suggested change
When I run `wp config create --skip-salts --skip-check`
When I run `wp config create --skip-salts`

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:config-create Related to 'config create' command scope:testing Related to testing state:unconfirmed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite Compatibility

3 participants