Skip to content

Add check for SQLite driver missing in target folder#2440

Merged
adamziel merged 16 commits intotrunkfrom
fix/db-missing
Aug 4, 2025
Merged

Add check for SQLite driver missing in target folder#2440
adamziel merged 16 commits intotrunkfrom
fix/db-missing

Conversation

@zaerl
Copy link
Copy Markdown
Collaborator

@zaerl zaerl commented Jul 29, 2025

Motivation for the change, related issues

Context:

By running npx @wp-playground/cli@latest server server --mount-before-install=.:/wordpress --skip-wordpress-setup --skip-sqlite-setup without:

  1. Specifying a working WordPress
  2. Specifying a SQLite working driver

The CLI crashed. Now, more safety checks take into consideration:

  1. If the user did not pass --skip-sqlite-setup, it checks if the mu-plugins folder exists in the target folder
  2. If it skips everything, it does not crash but returns a more insightful error to explain the situation

Implementation details

Testing Instructions (or ideally a Blueprint)

Choose a working WordPress folder, such as a WordPress Studio one. It should work because the folder already has a sqlite driver inside:

npx nx run playground-cli:dev-node server --mount-before-install=~/Studio/your-test-site:/wordpress --skip-wordpress-setup --skip-sqlite-setup --debug

This should not crash, but tell you that "SQLite installation has been skipped and no SQLite mu-plugin has been found".

npx nx run playground-cli:dev-node server --mount-before-install=./an-empty-folder:/wordpress --skip-wordpress-setup --skip-sqlite-setup --debug

This should work. Notice the skip-sqlite-setup missing:

npx nx run playground-cli:dev-node server --mount-before-install=./a-test-site:/wordpress --skip-wordpress-setup --debug

Other combinations should work as well.

@zaerl zaerl requested a review from a team as a code owner July 30, 2025 10:29
@zaerl zaerl requested review from adamziel and brandonpayton July 30, 2025 12:13
Copy link
Copy Markdown
Member

@JanJakes JanJakes left a comment

Choose a reason for hiding this comment

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

Looks good and works for me, thanks!

I only added a small idea about clarifying test descriptions a bit. Nothing critical.

rmdirSync(tempDir, { recursive: true });
});

it('should not start WordPress without a working driver module', async () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Without taking a close look at the implementation, it's a bit hard for me to understand what each test case is doing. Maybe the messages could be a bit clearer?

My current understanding is something like this:

should not start WordPress without a working driver module
  -> should not start WordPress when SQLite ZIP not specified and SQLite driver directory doesn't exist

should install WordPress with data but without specifying a driver module
  -> should install WordPress when SQL data path specified, even without SQLite ZIP path or SQLite driver directory

should fail if the SQLite integration plugin is specified but not installed
  -> should fail when the SQLite driver directory exists, but doesn't contain a valid driver

I may be wrong with some of these transcriptions; just wondering if we could make the messages super-clear.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, thanks.

!options.sqliteIntegrationPluginZip &&
!php.isDir(sqlitePluginPath)
) {
throw new Error('SQLite integration plugin is not installed.');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Playground CLI also supports MySQL sites so we can't assume that missing the SQLite plugin is always the error cause. We'll need to somehow decide what was the user intention.

Copy link
Copy Markdown
Collaborator Author

@zaerl zaerl Jul 31, 2025

Choose a reason for hiding this comment

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

If SQLite is not installed, check if the current connection is not working by using $wpdb->check_connection() and why. If it's a problem of connection with a MySQL database (credentials, ping, etc.) generate a specific error. Otherwise the generic one.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sounds like a good direction! Perhaps we could always check the database connection, even when the SQLite plugin is installed — we always need a working database after all

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I agree! I will make sure to add this as soon as possible.

@zaerl zaerl requested review from JanJakes and adamziel August 4, 2025 11:41
@zaerl
Copy link
Copy Markdown
Collaborator Author

zaerl commented Aug 4, 2025

I've added a more granular check in case of WordPress installation failure and a non-working DB connection:

  1. If the core SQLite driver is installed
  2. If SQLite installation has been skipped and a SQLite driver is in user folder, but not working
  3. Check MySQL connection if not using SQLite

@adamziel
Copy link
Copy Markdown
Collaborator

adamziel commented Aug 4, 2025

Thank you @zaerl! The logic looks pretty good and the test failures are unrelated to the code change. My only note is – the terms SQLite and MySQL seem to be used interchangeably. Let's revisit the boot.ts diff and make sure they're applied with rigor, e.g. in here we're not checking for SQLite specifically, but for any database connection. That's fine, but the comment talks about SQLite:

			// Check if the SQLite core integration has been installed.
			const validConnection = await isDatabaseConnectionValid(php);

@zaerl
Copy link
Copy Markdown
Collaborator Author

zaerl commented Aug 4, 2025

Thank you @zaerl! The logic looks pretty good and the test failures are unrelated to the code change. My only note is – the terms SQLite and MySQL seem to be used interchangeably. Let's revisit the boot.ts diff and make sure they're applied with rigor, e.g. in here we're not checking for SQLite specifically, but for any database connection. That's fine, but the comment talks about SQLite:

			// Check if the SQLite core integration has been installed.
			const validConnection = await isDatabaseConnectionValid(php);

Yep, you're right. It's a typo. There, we check if the $wpdb connection is running, MySQL or SQLite. Fixed.

@adamziel adamziel merged commit 8294e30 into trunk Aug 4, 2025
26 checks passed
@adamziel adamziel deleted the fix/db-missing branch August 4, 2025 19:46
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.

3 participants