| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\Database\Migrations; |
| 4 |
|
| 5 |
class BookingActivityMigrator |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Migrate the table. |
| 9 |
* |
| 10 |
* @return void |
| 11 |
*/ |
| 12 |
public static function migrate() |
| 13 |
{ |
| 14 |
global $wpdb; |
| 15 |
|
| 16 |
$charsetCollate = $wpdb->get_charset_collate(); |
| 17 |
|
| 18 |
$table = $wpdb->prefix .'fcal_booking_activity'; |
| 19 |
$indexPrefix = $wpdb->prefix .'fcal_ba_'; |
| 20 |
|
| 21 |
if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table)) != $table) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery |
| 22 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 23 |
$sql = "CREATE TABLE $table ( |
| 24 |
`id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, |
| 25 |
`booking_id` BIGINT UNSIGNED NOT NULL, |
| 26 |
`parent_id` BIGINT UNSIGNED NULL, |
| 27 |
`created_by` BIGINT UNSIGNED NULL, |
| 28 |
`status` VARCHAR(50) DEFAULT 'open', |
| 29 |
`type` VARCHAR(50) DEFAULT 'activity', |
| 30 |
`title` VARCHAR(192) NULL, |
| 31 |
`description` LONGTEXT NULL, |
| 32 |
`created_at` TIMESTAMP NULL, |
| 33 |
`updated_at` TIMESTAMP NULL, |
| 34 |
INDEX `{$indexPrefix}_mt_idx` (`booking_id`), |
| 35 |
INDEX `{$indexPrefix}_mto_type` (`type`) |
| 36 |
) $charsetCollate;"; |
| 37 |
|
| 38 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 39 |
|
| 40 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange -- dbDelta() is the safe schema-change wrapper. |
| 41 |
dbDelta($sql); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|