Create the database tables if they do not exist when resetting the DB#1285
Conversation
|
@kasparsd I don't believe it's strictly necessary, but it is nice and makes sense that a DB reset would make sure the tables are present and up to date. This is explicit where the other PR is implicit. |
I've been wondering if x+1 plugins with custom tables all do their "TABLE EXISTS" checks, does it have any real performance impact or not. In the big picture, it does seem kind of redundant to guard against a real far-edge case millions of times / year * # of plugins. |
|
@lkraav for this PR it'll happen when a user clicks a button, as for WP Admin or CLI it's pretty safe. On the frontend it can add up quickly on a busy site |
| } | ||
|
|
||
| // Create and update the database tables if they do not exist. | ||
| $this->plugin->install->check(); |
There was a problem hiding this comment.
Is this check here defined( 'DOING_AJAX' ) && DOING_AJAX going to stop this particular call from doing anything?
stream/classes/class-install.php
Lines 91 to 93 in f541b74
There was a problem hiding this comment.
🤦🏻 I wouldn't have noticed without your help :)
There was a problem hiding this comment.
Do you think $this->plugin->install->install( $this->plugin->get_version() ); might make more sense?
There was a problem hiding this comment.
Yes, that works. @tomjn Let me know if you'd like to patch or I can take over.
There was a problem hiding this comment.
@PatelUtkarsh it's been years since I looked at this, happy to hand over to you
Install::check() short-circuits on DOING_AJAX, making the existing defensive call inside wp_ajax_reset() a no-op when the tables are missing. Call install() directly so dbDelta recreates the schema before erase_stream_records() runs against it. dbDelta probes each table with DESCRIBE first and only runs CREATE TABLE when the table is missing, so calling install() when tables already exist is safe and idempotent. Per @tomjn's own 2021 suggestion in the original review thread.
Create the database tables if they do not exist when resetting the database
Fixes #1284
If the plugin is loaded without activation, tables are never created and resetting the database does not create tables. This PR changes that so that if tables are missing, a reset creates them.
Checklist
contributing.md).Release Changelog
Release Checklist
masterbranch.readme.txt.stream.php.Stable taginreadme.txt.classes/class-plugin.php.