| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yatra\Database\Tables; |
| 4 |
|
| 5 |
/** |
| 6 |
* BookingTravellers Table Class |
| 7 |
* |
| 8 |
* Represents the booking travellers table (wp_yatra_booking_travellers) containing |
| 9 |
* individual traveler records for each booking with indexing, |
| 10 |
* lead traveler designation, and relationship tracking. |
| 11 |
* |
| 12 |
* This table follows the new simplified pattern with only two static methods: |
| 13 |
* - getTableName(): Returns the prefixed table name |
| 14 |
* - getSchema(): Returns the complete CREATE TABLE SQL statement |
| 15 |
* |
| 16 |
* Usage: |
| 17 |
* BookingTravellersTable::getTableName() // Returns 'wp_yatra_booking_travellers' |
| 18 |
* BookingTravellersTable::getSchema() // Returns complete SQL schema |
| 19 |
* |
| 20 |
* @package Yatra\Database\Tables |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
class BookingTravellersTable extends BaseTable |
| 24 |
{ |
| 25 |
/** |
| 26 |
* Table name without prefix |
| 27 |
* |
| 28 |
* @var string The base table name without WordPress prefix |
| 29 |
*/ |
| 30 |
protected static string $table = 'yatra_booking_travellers'; |
| 31 |
|
| 32 |
/** |
| 33 |
* Get the complete table schema as raw SQL CREATE TABLE statement |
| 34 |
* |
| 35 |
* Returns the full SQL schema for the booking travellers table using heredoc syntax |
| 36 |
* for proper IDE syntax highlighting. Includes all columns, indexes, |
| 37 |
* and constraints from the original Database.php schema. |
| 38 |
* |
| 39 |
* @return string Complete CREATE TABLE SQL statement |
| 40 |
*/ |
| 41 |
public static function getSchema(): string |
| 42 |
{ |
| 43 |
$tableName = static::getTableName(); |
| 44 |
$charsetCollate = static::getCharsetCollate(); |
| 45 |
|
| 46 |
return <<<SQL |
| 47 |
CREATE TABLE IF NOT EXISTS `{$tableName}` ( |
| 48 |
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
| 49 |
`booking_id` bigint(20) UNSIGNED NOT NULL, |
| 50 |
`traveller_index` smallint(5) UNSIGNED NOT NULL DEFAULT 0, |
| 51 |
`is_lead` tinyint(1) NOT NULL DEFAULT 0, |
| 52 |
`created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| 53 |
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 54 |
|
| 55 |
PRIMARY KEY (`id`), |
| 56 |
KEY `idx_booking_id` (`booking_id`), |
| 57 |
KEY `idx_is_lead` (`is_lead`), |
| 58 |
KEY `idx_booking_index` (`booking_id`, `traveller_index`) |
| 59 |
) {$charsetCollate} COMMENT='Individual travellers for each booking'; |
| 60 |
SQL; |
| 61 |
} |
| 62 |
} |
| 63 |
|