Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (8)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change updates SQLite charset and collation initialization, adds ChangesCharset and collation handling
Native parser test setup
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to The change consistently exposes the intended SQLite charset and collation and configures parser loading for child PHP processes. No concrete merge-blocking issue is established; normal CI checks should pass before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The changes are bounded to database initialization, collation metadata, and the test environment. No introduced security weakness was identified. Downstream import behavior and interrupted initialization were not validated in a deployed environment, so some uncertainty remains. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 7 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 PHPMD (2.15.0)packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.phpPHPMD could not process this file (exit code 255): PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in phar:///usr/bin/phpmd/vendor/pdepend/pdepend/src/main/php/PDepend/Util/Cache/Driver/FileCacheDriver.php on line 209 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 |
utf8mb4_0900_ai_ci collation in tables created by WordPress
7a5e90c to
bb38a26
Compare
With DB_CHARSET 'utf8' and an empty DB_COLLATE, $wpdb->collate stayed empty, because the charset was only initialized before connecting, when wpdb::determine_charset() doesn't resolve it. Tables created with get_charset_collate() then got the MySQL 8-only utf8mb4_0900_ai_ci collation, which fails to import into MariaDB. SQLite stores all text as UTF-8 and the emulated connection always uses utf8mb4, so the charset and collation don't depend on the connection. Resolve them to utf8mb4 with utf8mb4_unicode_520_ci (or a configured UTF-8 collation) in init_charset(). This also applies while the driver connects, when it may reconstruct WordPress tables with wp_get_db_schema(). The DB_COLLATE tests run in separate processes. In CI, load the native parser extension from an INI file, so that these processes load it too, and avoid a PHP 8.5 deprecation in the native parser check that fails them. Reported in Automattic/studio#4737
WordPress uses utf8mb4_unicode_520_ci by default, but it was missing from INFORMATION_SCHEMA.COLLATIONS and SHOW COLLATION.
bb38a26 to
7228d44
Compare
Summary
With the SQLite driver,
$wpdb->collateis empty, so$wpdb->get_charset_collate()returnsDEFAULT CHARACTER SET utf8mb4without aCOLLATEclause. Tables created with it (for example, viadbDelta()) therefore use the emulated MySQL 8 default,utf8mb4_0900_ai_ci. MariaDB doesn't support this collation, so these tables fail to import there, including when pushing a WordPress Studio site to WordPress.com.This PR makes
$wpdbuse the same charset and collation as WordPress on MySQL:$wpdb->charsetis alwaysutf8mb4, matching the emulated connection.DB_CHARSETis ignored.$wpdb->collateisutf8mb4_unicode_520_ci, unlessDB_COLLATEspecifies another UTF-8 collation. For example,utf8_binbecomesutf8mb4_bin, as inwpdb::determine_charset().utf8mb4_unicode_520_ciis listed inINFORMATION_SCHEMA.COLLATIONSandSHOW COLLATION.Why
Previously,
WP_SQLite_DBinitialized the charset only before connecting. At that point,wpdb::determine_charset()leaves the values unchanged, so the collation stayed empty. The values are now resolved without a connection, since SQLite always uses UTF-8 and needs no server capability checks. This also makes them available while connecting, when the driver may reconstruct WordPress tables withwp_get_db_schema().Calling
init_charset()again after connecting, aswpdb::db_connect()does, wouldn't be enough: WordPress Studio may defineDB_CHARSETin a mu-plugin that loads later.This PR leaves the following unchanged:
CREATE TABLE) still useutf8mb4_0900_ai_ci, the emulated MySQL 8 default.utf8mb4_0900_ai_ci. Exports use only the table collation.Broader charset and collation support is tracked in #456.
Alternative to #511.
Related to Automattic/studio#4737.
Summary by CodeRabbit
utf8mb4and the appropriate collation, includingutf8mb4_unicode_520_ci.utf8mb4_unicode_520_cicollation in collation metadata.