Skip to content

Studio overwrites custom db.php drop-ins on every site start #3094

Description

@chubes4

Summary

keepSqliteIntegrationUpdated() unconditionally overwrites wp-content/db.php with the stock SQLite drop-in on every site start, site stop, import, export, push, and pull operation. This makes it impossible to use a custom database drop-in that extends the SQLite integration.

Impact

The markdown-database-integration plugin provides a custom db.php that extends WP_SQLite_DB and WP_SQLite_Driver to use markdown files as the source of truth with in-memory SQLite as the runtime query engine. It depends on the SQLite mu-plugin's driver classes but replaces db.php with its own drop-in.

Every time Studio touches the site, it overwrites the custom db.php, causing:

  1. The site boots with the stock SQLite driver instead of the custom one
  2. The custom storage layer is bypassed, causing data loss (posts stored as markdown files become invisible)
  3. The user has to manually reinstall db.php after every restart

Root Cause

In tools/common/lib/sqlite-integration.ts:

async needsSqliteSetup(sitePath: string): Promise<boolean> {
    const hasDbPhp = fs.existsSync(path.join(sitePath, 'wp-content', 'db.php'));
    const hasWpConfig = fs.existsSync(path.join(sitePath, 'wp-config.php'));
    return hasDbPhp || !hasWpConfig;
}

This returns true when db.php exists, which triggers installSqliteIntegration() which unconditionally overwrites db.php from db.copy. There is no check for whether the existing db.php is a custom drop-in.

Proposed Fix

Before overwriting db.php, check if the existing file is a custom drop-in. A custom drop-in defines SQLITE_DB_DROPIN_VERSION (so the SQLite plugin recognizes it) but does NOT contain the stock auto-generated header comment. The fix:

  1. Add hasCustomDbDropin() method that reads db.php and checks for the stock header
  2. Skip overwriting db.php in installSqliteIntegration() if a custom drop-in is detected
  3. Still update the SQLite mu-plugin (custom drop-ins depend on those driver classes)

I have a working implementation with tests at tools/common/lib/sqlite-integration.ts — happy to open a PR.

How to Reproduce

  1. Create a site in Studio
  2. Replace wp-content/db.php with a custom version that defines SQLITE_DB_DROPIN_VERSION
  3. Run studio site start or restart via the desktop app
  4. Observe that db.php has been reverted to the stock version

Metadata

Metadata

Assignees

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions