| @@ -32,9 +32,10 @@ | ||
| 32 | 32 | `created_at` TIMESTAMP NULL, |
| 33 | 33 | `updated_at` TIMESTAMP NULL, |
| 34 | 34 | INDEX `post_id` (`post_id`), |
| 35 | 35 | INDEX `status` (`status`), |
| 36 | - INDEX `type` (`type`) | |
| 36 | + INDEX `type` (`type`), | |
| 37 | + INDEX `user_id` (`user_id`) | |
| 37 | 38 | ) $charsetCollate;"; |
| 38 | 39 | dbDelta($sql); |
| 39 | 40 | } else { |
| 40 | 41 | // check if meta is exist or not |
| @@ -40,8 +41,14 @@ | ||
| 40 | 41 | // check if meta is exist or not |
| 41 | 42 | $isMigrated = $wpdb->get_col($wpdb->prepare("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND COLUMN_NAME='meta' AND TABLE_NAME=%s", $table)); |
| 42 | 43 | if(!$isMigrated) { |
| 43 | 44 | $wpdb->query("ALTER TABLE {$table} ADD COLUMN `meta` LONGTEXT NULL AFTER `message_rendered`"); |
| 45 | + } | |
| 46 | + | |
| 47 | + // check if the user_id index exists or not | |
| 48 | + $hasUserIdIndex = $wpdb->get_col($wpdb->prepare("SELECT INDEX_NAME FROM information_schema.STATISTICS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=%s AND INDEX_NAME='user_id'", $table)); | |
| 49 | + if (!$hasUserIdIndex) { | |
| 50 | + $wpdb->query("ALTER TABLE {$table} ADD INDEX `user_id` (`user_id`)"); | |
| 44 | 51 | } |
| 45 | 52 | } |
| 46 | 53 | } |
| 47 | 54 | } |