| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\Database\Migrations; |
| 4 |
|
| 5 |
class NotificationsMigrator |
| 6 |
{ |
| 7 |
static $tableName = 'fs_notifications'; |
| 8 |
|
| 9 |
public static function migrate() |
| 10 |
{ |
| 11 |
global $wpdb; |
| 12 |
|
| 13 |
$charsetCollate = $wpdb->get_charset_collate(); |
| 14 |
$table = $wpdb->prefix . static::$tableName; |
| 15 |
|
| 16 |
if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table)) !== $table) { |
| 17 |
$sql = "CREATE TABLE $table ( |
| 18 |
`id` BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, |
| 19 |
`actor_id` BIGINT(20) UNSIGNED NULL, |
| 20 |
`ticket_id` BIGINT(20) UNSIGNED NULL, |
| 21 |
`conversation_id` BIGINT(20) UNSIGNED NULL, |
| 22 |
`event_type` VARCHAR(192) NOT NULL, |
| 23 |
`category` VARCHAR(100) NOT NULL, |
| 24 |
`payload` LONGTEXT NULL, |
| 25 |
`created_at` TIMESTAMP NULL, |
| 26 |
`updated_at` TIMESTAMP NULL, |
| 27 |
INDEX `idx_conversation_id` (`conversation_id`), |
| 28 |
INDEX `idx_event_type` (`event_type`), |
| 29 |
INDEX `idx_created_at` (`created_at`), |
| 30 |
INDEX `idx_category_created_at` (`category`, `created_at`), |
| 31 |
INDEX `idx_ticket_created_at` (`ticket_id`, `created_at`) |
| 32 |
) $charsetCollate;"; |
| 33 |
|
| 34 |
return dbDelta($sql); |
| 35 |
} |
| 36 |
|
| 37 |
return false; |
| 38 |
} |
| 39 |
} |
| 40 |
|