Menu

Schema migrations in WordPress that never take your site down
📰

Schema migrations in WordPress that never take your site down

DEV Community: php·Roel van Distel·3 days ago
#TKNa6Die
#devto#dev#version#table#request
Long article (1566 words) — no AI summary yet.
Reading 0:00
15s threshold

One morning in October we deployed a new version of one of our plugins. A few minutes later the site stopped answering. Not slow: stopped. Every PHP worker was busy, every new request queued behind them, and the only way out was restarting PHP.

The cause was four lines of code that almost every WordPress plugin has in some form:

add_action ( 'plugins_loaded' , function ( ) { if ( get_option ( 'my_plugin_db_version' ) !== '1.30.0' ) { my_plugin_create_tables ( ) ; // dbDelta, ALTER TABLE update_option ( 'my_plugin_db_version' , '1.30.0' ) ; } } ) ;

Enter fullscreen mode

Exit fullscreen mode

This post is about why that pattern is dangerous on a busy site, and the small runner we replaced it with. We run Transtoyou , an online health platform in 14 languages on one WordPress multisite, so a broken deploy means patients who cannot reach a doctor. But nothing here is specific to health.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.