| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yatra\Database\Tables; |
| 4 |
|
| 5 |
/** |
| 6 |
* BookingDepartures Table Class |
| 7 |
* |
| 8 |
* Represents the booking-departures relationship table (wp_yatra_booking_departures) |
| 9 |
* linking bookings to specific trip departures with date and time information. |
| 10 |
* This table manages the association between bookings and scheduled departures. |
| 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 |
* BookingDeparturesTable::getTableName() // Returns 'wp_yatra_booking_departures' |
| 18 |
* BookingDeparturesTable::getSchema() // Returns complete SQL schema |
| 19 |
* |
| 20 |
* @package Yatra\Database\Tables |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
class BookingDeparturesTable 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_departures'; |
| 31 |
|
| 32 |
/** |
| 33 |
* Get the complete table schema as raw SQL CREATE TABLE statement |
| 34 |
* |
| 35 |
* Returns the full SQL schema for the booking-departures table using heredoc syntax |
| 36 |
* for proper IDE syntax highlighting. Includes all columns, indexes, |
| 37 |
* and constraints. |
| 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 |
`departure_id` bigint(20) UNSIGNED NOT NULL, |
| 51 |
`travel_date` date NOT NULL, |
| 52 |
`departure_time` time DEFAULT NULL, |
| 53 |
`created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| 54 |
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 55 |
|
| 56 |
PRIMARY KEY (`id`), |
| 57 |
UNIQUE KEY `unique_booking_departure` (`booking_id`,`departure_id`), |
| 58 |
KEY `idx_booking_id` (`booking_id`), |
| 59 |
KEY `idx_departure_id` (`departure_id`), |
| 60 |
KEY `idx_travel_date` (`travel_date`) |
| 61 |
) {$charsetCollate} COMMENT='Booking-Departure relationship'; |
| 62 |
SQL; |
| 63 |
} |
| 64 |
} |
| 65 |
|