| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\Database\Migrations; |
| 4 |
|
| 5 |
class NotificationUsersMigrator |
| 6 |
{ |
| 7 |
static $tableName = 'fs_notification_users'; |
| 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 |
`notification_id` BIGINT(20) UNSIGNED NOT NULL, |
| 20 |
`user_id` BIGINT(20) UNSIGNED NOT NULL, |
| 21 |
`channel` VARCHAR(100) NOT NULL DEFAULT 'web', |
| 22 |
`is_read` TINYINT(1) NOT NULL DEFAULT 0, |
| 23 |
`read_at` TIMESTAMP NULL, |
| 24 |
`created_at` TIMESTAMP NULL, |
| 25 |
`updated_at` TIMESTAMP NULL, |
| 26 |
INDEX `idx_notification_id` (`notification_id`), |
| 27 |
INDEX `idx_user_id` (`user_id`), |
| 28 |
INDEX `idx_user_is_read_created_at` (`user_id`, `is_read`, `created_at`), |
| 29 |
INDEX `idx_user_notification_id` (`user_id`, `notification_id`), |
| 30 |
UNIQUE KEY `uniq_notification_user` (`notification_id`, `user_id`) |
| 31 |
) $charsetCollate;"; |
| 32 |
|
| 33 |
return dbDelta($sql); |
| 34 |
} |
| 35 |
|
| 36 |
return false; |
| 37 |
} |
| 38 |
} |
| 39 |
|